diff --git a/api/components/IsoDateInput.vue b/api/components/IsoDateInput.vue index 48ed355..ac873e0 100644 --- a/api/components/IsoDateInput.vue +++ b/api/components/IsoDateInput.vue @@ -54,7 +54,7 @@ export default defineComponent({ label: { type: String, default: 'Datum' }, readonly: Boolean, rules: { - type: Array as PropType, + type: Array as PropType[]>, default: () => [], }, }, @@ -62,7 +62,21 @@ export default defineComponent({ setup(props, { emit, attrs }) { const customRules = computed(() => [ props.type == 'date' ? stringIsDate : props.type == 'time' ? stringIsTime : stringIsDateTime, - ...props.rules, + (value?: string | null) => { + 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])); + } + props.rules.forEach((rule) => { + const r = rule(date); + if (typeof r === 'string') return r; + }); + } + }, ]); const clearable = computed(() => diff --git a/api/src/utils/validators.ts b/api/src/utils/validators.ts index e77a436..2db8e8c 100644 --- a/api/src/utils/validators.ts +++ b/api/src/utils/validators.ts @@ -1,4 +1,4 @@ -export type Validator = (value: unknown) => boolean | string; +export type Validator = (value?: T | null) => boolean | string; export function notEmpty(val: unknown) { return !!val || 'Feld darf nicht leer sein!';