Persistent Validation Errors After Failed Submission with react-hook-form, shadcn and Zod #11112
-
I'm facing an issue with react-hook-form, shadcn and Zod where validation errors persist even after a failed form submission. The problem occurs when I submit a form with incorrect data to the server (Action - Remix v2), and then on a subsequent submit attempt without changing any fields, the form still reports "Required" errors, even though the fields are still filled. You can watch it here. It appears that the issue might be related to the loss of form values after a failed submission. Despite various attempts to clear errors or reset the form, the values are lost, causing persistent validation errors. I would appreciate any guidance or insight on how to address this issue effectively, as it affects the user experience and development workflow. If there's a known solution or if this is indeed a bug, I'd like to better understand how to resolve it. OBS: Interestingly, if I use
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Same here. My god this is annoying. |
Beta Was this translation helpful? Give feedback.
-
Hello! I saw a tutorial from Jack Herrington talking about this issue a few weeks back: Basically if the submission fails you send back the fields from the server and set them as defaultValues. I'm using Next.js with server actions, but it may be of some guidance. :) Client side
On the server
|
Beta Was this translation helpful? Give feedback.
Hello! I saw a tutorial from Jack Herrington talking about this issue a few weeks back:
https://youtu.be/VLk45JBe8L8?feature=shared&t=684
Basically if the submission fails you send back the fields from the server and set them as defaultValues.
I'm using Next.js with server actions, but it may be of some guidance. :)
Client side