Closed vimtor closed 1 year ago
Also came to this error. The missing update is not the only thing that is wrong here.
The field array errors should be put into a "root" object.
With the current implementation of zodResolver
, it always sets message
and type
for the field array and if this happens, all the other errors of its items are gone (but seems to be related to refine/superRefine for fieldArrays).
You need to manually invoke the trigger
method when adding to the field array. Validation doesn't occur automatically when a new field is registered.
https://codesandbox.io/s/react-hook-form-array-length-error-zod-forked-zjx7g7?file=/src/App.tsx
Hi @jorisre!
I'm not trying to be mean, and I am super grateful that you and others developed react-hook-form
. It's such a great library.
However, I think that the fact that the trigger
is not invoked automatically when adding to a field array is in fact the issue. It seems to me that invoking the trigger
manually is a workaround.
Thank you.
Describe the bug
Zod array length validation does not trigger when using the
append
method fromuseFieldArray
.To Reproduce
zod
and@hookform/resolvers
for validation.useFieldArray
.zod
schema for this field and set a minimum length for the array length AND a validation for the objects in the array.Codesandbox link (Required)
https://codesandbox.io/s/react-hook-form-array-length-error-zod-b92w1t
Expected behavior A clear and concise description of what you expected to happen.
I should be able to validate the array length and its contents using
Screenshots
https://github.com/react-hook-form/react-hook-form/assets/36263538/949d8419-bc07-42a8-8b81-4973dbe9ea0e
Desktop (please complete the following information):