-
Notifications
You must be signed in to change notification settings - Fork 4.6k
useFormValidity: fix nesting levels
#72588
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
Conversation
6df982a to
9a5462c
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Extracted #72848 to simplify this PR. |
9a5462c to
2631768
Compare
| * | ||
| * @return Record of field IDs to error messages (undefined means no error). | ||
| */ | ||
| export function useFormValidity< Item >( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function has been completely refactored, so the diff would not be super helpful to understand what's actually changed. For review, I recommend just taking a look at how it works now and ignore the previous version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR would have been a good opportunity to refactor to delegate the validation behavior to the field types instead of centralizing it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR updates the core flow to fix the existing issue. Extracting the existing logic to the field type definitions is an extra thing on top of what this PR already does. The PR is already big as it is, so I thought I'd control scope by focusing just on fixing the issue.
| ) => { | ||
| return <DateControl { ...props } operator="between" />; | ||
| }; | ||
| const makeAsync = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of these little functions were updated, just moved around.
| required, | ||
| elements: elements !== 'none' ? true : false, | ||
| custom: maybeCustomRule( customTelephoneRule ), | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also moved some fields around to better highlight and group them in the validation story.
| required, | ||
| elements: elements !== 'none' ? true : false, | ||
| { | ||
| id: 'array', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed countries to array because any other field type just uses the type as the id/label.
|
|
||
| const form = useMemo( | ||
| () => ( { | ||
| fields: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fields array is the relevant change for this story. Added some nested fields.
jorgefilipecosta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments for consideration but things tested well for me 👍
2631768 to
e2c279c
Compare
|
Thanks for your review @jorgefilipecosta! I've addressed all your comments, and set this up for auto-merge. |
|
Flaky tests detected in e2c279c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19063367555
|
Follow-up to #71412, #72848
What?
This PR makes the
useFormValidityhook work for any nested level.Why?
It was only working for fields up to one nesting level.
All fields here were validated:
In this case, all fields but
fieldAtLevel2were validated:How
No API changes.
useFormValidityhas been updated to work recursively and work at any nesting level.Testing Instructions
npm run storybook:dev), and navigate to "DataViews > DataForm > Validation". Verify the validation messages are triggered as expected.The story has been updated so that some fields have up to 4 nesting levels. If you want to reproduce the issue in
trunkpaste the existing form config there and observe how fields with nested levels > 2 were not validated.