`field.state.meta.isValid` not updated when validating on the server
field.state.meta.isValid
is true in Next.js after server validation, unless I also apply the same validation on the client. Shouldn't that state be merged by mergeForm
? Would be a lot easier DX if I could just rely on field.state.meta.isValid
and field.state.meta.errors
instead of having to merge those manually.5 Replies
fascinating-indigoOP•7d ago
This is what I'm currently having to use to get to the
username
field errors... does anybody know of a better way? This seems strange:
fascinating-indigo•7d ago
it should be, yeah. What is the error generated in the nextjs validation?
fascinating-indigoOP•6d ago
no error, it showed as valid even if the server validation failed - i just assumed i couldn't rely on
field.state.meta.isValid
if I only validated it on the server, so I passed the same zod schema to the client validator as wellfascinating-indigo•6d ago
could you share your server validate? I‘ll see if there‘s a problem with it this evening or tomorrow
ratty-blush•5d ago
I have the same problem. Looks like there are a couple of issues in the repo about it:
- FieldAPI: state.meta.errors are not updating properly when using server-validations for errors
- Zod refine errors with specific paths aren't propagated to field error states
- Zod errors from server action aren't propagated to field error.
And even a PR.
For now, I'm handling it manually, getting the error from the field
meta
for the client side validation and the form errorMap
for the server side validation. Something like this:
But it would be nice if the mapping was handled by mergeForm
, to get the field specific errors sent by the server validation in its respective field meta