Issue #1571 Handle the case where the date is invalid

This commit is contained in:
Massedil 2024-11-04 20:47:19 +01:00
parent f236ec3a2d
commit 9992286e7e

View file

@ -1,7 +1,7 @@
<template> <template>
<input <input
type="datetime-local" type="datetime-local"
class="rounded" class="rounded invalid:border-red-500"
v-model="component" v-model="component"
:min="computeMin" :min="computeMin"
@blur="$emit('blur')" @blur="$emit('blur')"
@ -12,8 +12,8 @@ import { computed } from "vue";
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
modelValue: Date; modelValue: Date | null;
min?: Date | undefined; min?: Date | null | undefined;
}>(), }>(),
{ {
min: undefined, min: undefined,
@ -30,10 +30,19 @@ const UTCToLocal = (date: Date) => {
const component = computed({ const component = computed({
get() { get() {
if (!props.modelValue) {
return null;
}
return UTCToLocal(props.modelValue); return UTCToLocal(props.modelValue);
}, },
set(value) { set(value) {
emit("update:modelValue", new Date(value)); console.log("value" + value);
if (!value) {
emit("update:modelValue", null);
return;
}
const date = new Date(value);
emit("update:modelValue", date);
}, },
}); });