resolvers icon indicating copy to clipboard operation
resolvers copied to clipboard

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

Open stefan-girlich opened this issue 1 year ago • 2 comments

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.

stefan-girlich avatar Mar 25 '24 14:03 stefan-girlich

I have same issue https://github.com/react-hook-form/react-hook-form/issues/11833

upauliushchyk avatar Apr 30 '24 12:04 upauliushchyk

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.

SamSlotemaker avatar Jun 17 '24 10:06 SamSlotemaker