Compare commits
1 Commits
50fba1a909
...
fca79c36ef
Author | SHA1 | Date |
---|---|---|
Ferdinand Thiessen | fca79c36ef |
|
@ -54,7 +54,7 @@ export default defineComponent({
|
|||
label: { type: String, default: 'Datum' },
|
||||
readonly: Boolean,
|
||||
rules: {
|
||||
type: Array as PropType<Validator[]>,
|
||||
type: Array as PropType<Validator<Date>[]>,
|
||||
default: () => [],
|
||||
},
|
||||
},
|
||||
|
@ -62,7 +62,22 @@ export default defineComponent({
|
|||
setup(props, { emit, attrs }) {
|
||||
const customRules = computed(() => [
|
||||
props.type == 'date' ? stringIsDate : props.type == 'time' ? stringIsTime : stringIsDateTime,
|
||||
...props.rules,
|
||||
(value?: string) => {
|
||||
if (props.rules.length > 0 && !!value) {
|
||||
let date: Date | undefined = undefined;
|
||||
if (props.type == 'date') date = modifyDate(value);
|
||||
else if (props.type == 'time') date = modifyTime(value);
|
||||
else {
|
||||
const split = value.split(' ');
|
||||
date = modifyTime(split[1], modifyDate(split[0]));
|
||||
}
|
||||
for (const rule of props.rules) {
|
||||
const r = rule(date);
|
||||
if (typeof r === 'string') return r;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
const clearable = computed(() =>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export type Validator = (value: unknown) => boolean | string;
|
||||
export type Validator<T = unknown> = (value?: T | null) => boolean | string;
|
||||
|
||||
export function notEmpty(val: unknown) {
|
||||
return !!val || 'Feld darf nicht leer sein!';
|
||||
|
|
Loading…
Reference in New Issue