Skip to content

Error Handling in useFieldArray with Root Error #629

@KrabDr

Description

@KrabDr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions