You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello i am trying to validate date but i want it optional that means if the user enter a date then validate it but if he/she left it with no value i don't want to validate it. birth_date: zod.date().optional(),
that's not worked for me
The text was updated successfully, but these errors were encountered:
My guess is that the form is returning a default value of "" when no input is entered into the form. There's a few ways to handle this:
constschema=z.object({birth_date: z.date().optional().catch(undefined),// any error will cause `undefined` to be returnedbirth_date: z.preprocess(val=>val==="" ? undefined : val,z.date().optional())// convert empty string to undefined with preprocess})
Hello i am trying to validate date but i want it optional that means if the user enter a date then validate it but if he/she left it with no value i don't want to validate it.
birth_date: zod.date().optional(),
that's not worked for me
The text was updated successfully, but these errors were encountered: