Using setError with a custom resolver #12735
Unanswered
stefan-girlich
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am using
zodResolver
from@hookform/resolvers/zod
with RHF on the frontend and in my API middleware.I am applying a duplicate/uniqueness check on a field that may pass in the frontend, but fail in the middleware if a conflicting entity with has been created after page load. tldr; you enter "My unique name" in the FE, pass validation, but in the middleware we find out "My unique name" has already been used.
I am returning the corresponding validation error (
ZodIssue
) as an API response and I want to usesetError
to highlight the error as if it had been detected before submission.The docs state that validation will still pass if the local check is passed, making it sound like
setError
rather acts likesetErrorMessage
.Calling
setError('my_field', { message: 'Error!', type: 'custom' })
after submission (and thus, after server validation) indeed does not have any effect. In fact, even callingsetError('root.foo', { type: 'any error' })
does not updateerrors
returned fromuseForm
.What am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions