Next.js Discord

Discord Forum

Form validation help

Unanswered
American Dipper posted this in #help-forum
Open in Discord
American DipperOP
I have zod setup for both client-side and server-side validation of my form. However I want to keep basic HTML form validation if user doesn't have JS enabeled. The problem with setting 'required' attributes on my input fields is it is interfering with the zod validation and preventing the custom errror messages from showing below the form fields. Is there a workaround to ensure both function as intended? Thanks

4 Replies

Netherland Dwarf
Zod allows you to add optional fields
Just like a form
If your using react hook form all you need is to add a field in the hook called resolver and pass the resolver object which you can import from zod
And zod will connect to react hook form and auto display all errors related