react-hook-form / resolvers

📋 Validation resolvers: Yup, Zod, Superstruct, Joi, Vest, Class Validator, io-ts, Nope, computed-types, typanion, Ajv, TypeBox, ArkType, Valibot, effect-ts and VineJS
https://react-hook-form.com/
MIT License
1.71k stars 155 forks source link

Error Handling in useFieldArray with Root Error #629

Closed KrabDr closed 8 months ago

KrabDr commented 11 months ago

Describe the bug Currently, there is an issue with error handling within useFieldArray, where errors associated with the root error are not functioning as expected.

To Reproduce Steps to reproduce the behavior:

  1. Go to Codesandbox
  2. Click on submit button
  3. Observe that the error from the second field is displayed under the first field.

Codesandbox link (Required) Sandbox demonstrating the issue: Codesandbox

Expected behavior Sandbox with the expected behavior: Codesandbox

Upon investigation, it appears that the issue arises from the removal of empty values within an array before setting errors inside toNestErrors. When used within Object.assign, it results in errors being assigned to incorrect keys.

Versions

react-hook-form: 7.45.2 @hookform/resolvers: 3.3.1