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

fix: isNameInFieldArray with names option #713

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YuyaYoshioka
Copy link

@YuyaYoshioka YuyaYoshioka commented Aug 31, 2024

Issue

Details

Because of #621, nested object error becomes not consistent when a key of the object is used in option.names.

To Reproduce

  1. go to codesandbox
  2. type "A" and click submit button
  3. you can see error.name.root.message because "name" is used in deps
  4. type "B"
  5. you can see error.name.message

changes

  • fix logic of isNameInFieldArray
  • add test for toNestErrors with names option

@YuyaYoshioka YuyaYoshioka changed the title fix: add support for names option fix: isNameInFieldArray for names option Aug 31, 2024
@YuyaYoshioka YuyaYoshioka changed the title fix: isNameInFieldArray for names option fix: isNameInFieldArray with names option Aug 31, 2024
@@ -38,4 +38,4 @@ export const toNestErrors = <TFieldValues extends FieldValues>(
const isNameInFieldArray = (
names: InternalFieldName[],
name: InternalFieldName,
) => names.some((n) => n.startsWith(name + '.'));
) => names.some((n) => n.match(`^${name}\\.\\d+`));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n should contain number in field array.

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

Successfully merging this pull request may close these issues.

1 participant