Open LeclechM opened 2 months ago
That's because radix-vue's Date Picker uses @internationalized/date only. I'm facing the same issue. I can't set initial values because of that, and Zod doesn't support such objects.
That's because radix-vue's Date Picker uses @internationalized/date only. I'm facing the same issue. I can't set initial values because of that, and Zod doesn't support such objects.
I'm experiencing the same issue now. Is there no solution for this? Even though the documentation says, If you want to set the default value of a date, convert it to a Date first using new Date(val),
I'm still getting an error.
Since the component relies on DateValue from @internationalized/date, I've implemented a temporary solution to address this issue. Thanks for @Keiishu
Revised
import { getLocalTimeZone, parseAbsolute } from "@internationalized/date";
const schema = z.object({
date: z
.any() // for all possibilities value (in case: DateValue type from @internationalized/date)
.refine((val) => val, 'Invalid Date'), // Ensure the 'date' field is required
});
const form = useForm({
validationSchema: toTypedSchema(schema), // for validation
initialValues: {
date: parseAbsolute(new Date().toISOString(), getLocalTimeZone()),
},
});
And in the template, define the date input like this:
<template #date="slotProps">
<AutoFormFieldDate v-bind="slotProps" required />
</template>
Reproduction
https://stackblitz.com/edit/nuxt-vue-3-4-beta-twkyrr?file=src%2Fpages%2Fhome%2FHomePage.vue
Describe the bug
In documentation:
An error occurs during
{{ slotProps.componentField.modelValue ? df.format(slotProps.componentField.modelValue.toDate(getLocalTimeZone())) : "Pick a date" }}
because slotProps.componentField.modelValue is of type string and not a DateValue like expected by Calendar component.
System Info
Contributes