Luan Mário - how to make an input of type date ...
how to make an input of type date optional?
5 Replies
does not work
return invalid date error when submitting the form
I'm using z.coerce.date
Well,
coerce
runs whatever it gets through new Date
, and if you pass undefined
or null
through that, you'll probably find you get an invalid date.
Personally I would really avoid using coerce
, as it makes the schema a bit weird and unpredictable. Much better to just make sure the data-types you hand to the schema are correct to begin with.
In the case of a form, write it so that the form state contains strings, numbers, and dates as you'd expect. Not "whatever the form feels like".It is a problem that there is an entry of type date. in the api query for the editing screen, data in the format 2007-06-24T00:00:00 may or may not appear
Then
coerce
is not the right thing to use. It's specifically string
you want to convert to Date
, so then it's probably safer to use z.preprocess
, or something like that.