-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Dataforms: Add pattern validation. #73156
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
|
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. |
5dac2fe to
dcc46b0
Compare
Nah, it's good to start with opinionated messages. When/If we do this, any other existing rule also need it, so we may want to look at this separately. |
| ); | ||
|
|
||
| // Convert pattern to string if it's a RegExp | ||
| let pattern; |
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.
In addition to per-control validation, the useFormValidity hook must return the same error in the validity prop and isValid false. This is demonstrated in the storybook by controlling the "save button" (it's disabled if the form is invalid).
We need strings for the fields to be serializable. Supporting Regexp objects is nice, I agree. It's fine by me to support both from the outset, and I don't see any issues. Though, I also wonder if they add anything really worth having that strings don't have (considering the serialization concerns). I'm going to summon @mcsf intuition about this. |
This is not a strong opinion, but just offhand I can think of the fact that RegExp instances can carry flags, which are lost when extracting /^hello?$/i.source // "^hello?$"
/^hello?$/i.source === /^hello?$/g.source // trueWhich sounds like a point of confusion that we can avoid by only accepting strings. |
b506ca1 to
1567aa8
Compare
Good point @mcsf, I removed the RegExp possibility. |
|
Hi @oandregal, I applied your feedback and now on the storybook there is a control to enable pattern validation, the custom one should be set to none as together is hard to test. |
|
Flaky tests detected in aa0d102. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19508045220
|
aa0d102 to
556d2c1
Compare
2282091 to
4b3131a
Compare
oandregal
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.
Nice!
4b3131a to
61519a9
Compare
61519a9 to
2eb13e1
Compare
This reverts commit 1490580.
b9b1a59 to
18f035e
Compare
|
Thank you for the reviews @oandregal all the feedback was applied before the merge. |

Part of: #71500
This PR adds pattern based validation to all the fields that support it.
Some questions
When pattern validation fails the message is always: "Please match the requested format". Should we allows customizing this error message on the API?
Pattern on the api is pattern?: string | RegExp;. I think being able to provide a regex is nice, but in html it is always strings should we allow regex or force the consumer to pass a string?
cc: @oandregal
Testing Instructions
Execute
npm run storybook:devGo to http://localhost:50240/?path=/story/dataviews-dataform--validation.
Verify the fields with pattern validation work as expected.