Repository navigation
DataForm: treat combined form fields purely as layout containers #82175
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
Changes from all commits
aae4788
8d90c3e
0bfa039
c23dc45
39a9d3b
2ce2aeb
3997053
e84ed51
a47a119
d72b93f
d5ae6e5
0eb4813
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/13308 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/82175 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,37 @@ | |
|
|
||
| ## Unreleased | ||
|
|
||
| ### Breaking Changes | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've searched across a few repos I regularly work with that are consumers of this library (automattic/wp-calypso, woocommerce, jetpack) and found no affected cases. Even though I'd consider this a bug, I want to treat it as a breaking change to give consumers a heads-up and an example to migrate to the proper API, should there be anyone affected. |
||
|
|
||
| - DataForm: a combined form field (one with `children`) is now treated purely as a layout container. Its `id` is no longer resolved against the field definitions: a field sharing that `id` no longer contributes validation rules to the group, and the `panel` layout no longer uses it for the collapsed summary or `readOnly` state, falling back to the group's first leaf child instead ([#82175](https://github.com/WordPress/gutenberg/pull/82175)). | ||
|
|
||
| If a combined field relied on sharing its `id` with a field to pick the panel summary, declare it through `layout.summary` instead. For example, a `discussion` field whose `render` summarizes `comment_status` and `ping_status` together: | ||
|
|
||
| ```js | ||
| // Before: the summary came from the `discussion` field because the group shares its id. | ||
| const form = { | ||
| layout: { type: 'panel' }, | ||
| fields: [ | ||
| { id: 'discussion', children: [ 'comment_status', 'ping_status' ] }, | ||
| ], | ||
| }; | ||
|
|
||
| // After: the summary field is explicit. Without it, the group would | ||
| // now be summarized by its first child, `comment_status`. | ||
| const form = { | ||
| layout: { type: 'panel' }, | ||
| fields: [ | ||
| { | ||
| id: 'discussion', | ||
| layout: { type: 'panel', summary: 'discussion' }, | ||
| children: [ 'comment_status', 'ping_status' ], | ||
| }, | ||
| ], | ||
| }; | ||
| ``` | ||
|
|
||
| If a combined field relied on a same-id field's `isValid` rules being applied to the group, move those rules to the child fields. | ||
|
|
||
| ### Internal | ||
|
|
||
| - Remove unused dependency `@wordpress/primitives` ([#82103](https://github.com/WordPress/gutenberg/pull/82103)). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,19 +73,10 @@ function getFormFieldsToValidate< Item >( | |
| return null; | ||
| } | ||
|
|
||
| const fieldDef = fieldsMap.get( formField.id ); | ||
| if ( fieldDef ) { | ||
| const [ normalizedField ] = normalizeFields< Item >( [ | ||
| fieldDef, | ||
| ] ); | ||
|
|
||
| return { | ||
| id: formField.id, | ||
| children: processedChildren, | ||
| field: normalizedField, | ||
| } satisfies FormFieldToValidate< Item >; | ||
| } | ||
|
|
||
| // A combined form field is a layout container, not a field: | ||
| // its id is never resolved against the field definitions, so | ||
| // no validation rules are attached to it. Only its children | ||
| // are validated. | ||
|
Comment on lines
+76
to
+79
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to leave this comment to signal the change. |
||
| return { | ||
| id: formField.id, | ||
| children: processedChildren, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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 merge operation only adds the
layout(with the summary) to the respective fields (statusanddiscussion) but leaves the rest as it was in the 7.1 folder (children).