Z
Zod14mo ago
Luan Mário

Dealing with form input with z.coerce.date

Hey guys, How do I make z.coerce.date() required, with zod and react hook form
4 Replies
Scott Trinh
Scott Trinh14mo ago
Or do you want it to fail on undefined rather than trying to coerce it?
Luan Mário
Luan MárioOP14mo ago
I want the user to enter any date, but when they enter it the error disappears this date does not need to have a conditional. it just needs to be filled
Scott Trinh
Scott Trinh14mo ago
Oh, yeah, this is probably an issue because "required" means something different in TypeScript/Zod than in HTML forms. "empty" in HTML forms is "" where it's undefined in TypeScript/Zod. I don't have any direct advice to give here tho. You can probably use something like:
const maybeDate = z.string().min(1).pipe(z.coerce.date());
const maybeDate = z.string().min(1).pipe(z.coerce.date());
Want results from more Discord servers?
Add your server