jquense / yup

Dead simple Object schema validation
MIT License
22.72k stars 925 forks source link

How to check a date only when it is entered #2076

Open jdvsch opened 1 year ago

jdvsch commented 1 year ago

Hi,

I am using react-hook-form V7.44.3 and I am validating a date but its input is optional, I have tried the following: warranty_due_date: yup.date().optional(), warranty_due_date: yup.date().notRequired(),

but I keep getting an error: object { message: "warranty_due_date must be a date type, but the final value was: Invalid Date (cast from the value Invalid Date).", type: "typeError", ref: input#warranty_due_date.sc -hBxehG.eMfLfQ }

What should I do to avoid this error?

jquense commented 1 year ago

Doesn't seem like yup is the problem, from the error it's being passed an invalid date object