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

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

YuyaYoshioka
Copy link
Contributor

@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
Contributor 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.

Copy link
Member

@jorisre jorisre left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the fix

@jorisre jorisre merged commit 985c48d into react-hook-form:master Jan 27, 2025
1 check passed
Copy link
Contributor

🎉 This PR is included in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants