DataForm: Streamline validation behavior#71345
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. |
|
Flaky tests detected in 8b66d61. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/17231116306
|
| export { VIEW_LAYOUTS } from './dataviews-layouts'; | ||
| export { filterSortAndPaginate } from './filter-and-sort-data-view'; | ||
| export type * from './types'; | ||
| export { isItemValid } from './validation'; |
There was a problem hiding this comment.
I'd like to leave this export for now: it can be useful in non-reactive situations (e.g., to validate the form data on load).
There was a problem hiding this comment.
Ok works for me.
packages/dataviews/src/types.ts
Outdated
| value: Record< string, any >, | ||
| validation: { isValid: boolean } | ||
| ) => void; | ||
| applyChanges?: ( item: Item, changes: Partial< Item > ) => Item; |
There was a problem hiding this comment.
An idea that I decided to ditch :P
This reverts commit 55d79f3.
|
@youknowriad while working on adding support for async validation, I just realized this PR is problematic:
I'm working on addressing those in #71161. I'd like to revert this PR and focus on landing 71161 instead. |
What?
This PR proposes a better Dev Experience when working with DataForm and validation. Instead of assuming the consumer is going to run 'isltemValid' manually and think about when and how to run validation properly, this PR runs validation on each change and passes the result as a second argument for the onChange callback.
This is kind of inline with how most form libraries work, they take care of the validation... and they only give you a state.
Testing Instructions
There shouldn't be any impact, the only place that uses validation right now is the "reoder page" action. You can test that action quickly or the validation story in storybook.