Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zodResolver / superRefine / useFieldArray: useForm errors are not updated to reflect zodResolver errors #672

Open
stefan-girlich opened this issue Mar 25, 2024 · 2 comments

Comments

@stefan-girlich
Copy link

stefan-girlich commented Mar 25, 2024

Describe the bug
Only changes to the last field in a field array are considered for validation when using superRefine. Changes to other fields are validated by zodResolver, but the resulting errors are not updated.

To Reproduce
Rule for all scenarios: names must be unique

Scenario 1:

  1. Open sandbox link below
  2. Change second input to "foo" to provoke error
  3. Change first input to "bar" to resolve error
    => zodResolver error disappears, react-hook-form error remains (incorrectly)

Scenario 2:

  1. Open sandbox link below
  2. Change first input to "bar" to provoke error
    => react-hook-form errors are not updatefd (incorrectly)

Scenario 3 (positive):

  1. Open sandbox link below
  2. Change second input to "foo" to provoke error
  3. Change second input back to "bar" to resolve error
    => zodResolver and react-hook-form errors disappear

Codesandbox link (Required)
Link

Expected behavior
zodResolver error states are propagated to the useForm errors regardless of array position

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Brave
  • Version 1.63.169

Additional context
If the error state is reached by editing the first field (see scenario 2 above), the error from zodResolver is missing the ref object. This seems to be the missing link.

@upauliushchyk
Copy link

I have same issue react-hook-form/react-hook-form#11833

@SamSlotemaker
Copy link

Same issue for me:

I have an issue with the resolver incorrectly updating the formState errors with a superRefine.
In the sandbox I created, the rule is that all names should be unique, so it should error on every input that is not unique.

Link to sandbox: https://codesandbox.io/p/sandbox/musing-dust-zqv9mv?file=%2Fsrc%2Findex.tsx

Current behavior

when you click and blur the second input, the error only appears at the second input, but the console shows that the resolver found 2 errors, while the formState errors only gives one (leaves first array index empty), you can see this in the sandbox console and in the image I attached.

Then, when you blur the first input as well, the error appears on both. But when you now change a name so they are unique, only the edited error dissapears, while you expect both to dissapear.

Expected behavior

I expect both errors to appear when they are not unique, and both to dissapear when i change them to be unique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants