-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Bootstrap nested fields #71789
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
base: trunk
Are you sure you want to change the base?
Bootstrap nested fields #71789
Conversation
|
Flaky tests detected in 61aea31. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/17951265739
|
2d7ced3 to
287317f
Compare
|
Size Change: +2.02 kB (+0.1%) Total Size: 1.95 MB
ℹ️ View Unchanged
|
fe7dbd3 to
4f16049
Compare
7fb7645 to
06609ea
Compare
|
Hey @oandregal , This is a very meaningful update to the I really liked that in the example you created, you added both a list and another field outside the list (i.e. Total Amount). This matches perfectly our use case where we have a date picker field and then a list. A couple of notes: One of the things that I didn't fully explore when creating the DataForm with a custom Edit component was how to validate each field in the list, so I wanted to see how you handled it here. I understand that this is handled by The main reason why was that the Storybook example that opens in a modal behaves in an unexpected way for me: Screen.Capture.on.2025-09-25.at.09-22-54.mp4I think there are 3 potential types of validation that we need to consider here:
Which of those validation levels are supported now? Another question I have about extensibility, is around the "Add item" button. I noticed that this string is hardcoded -- is there a way to make it so each list has its own button text, like "Add product" or "Add time slots", depending on the context? |
|
I think that the new API is flexible and easy to grasp. Combining it with custom I've noticed that the buttons to add and remove rows are part of the new |
All of them. "Per individual field" + "Per row" can be addressed by implementing a custom function in any of the child fields. Note that
I'll fix this.
I suppose these two things are part of the same: we may want to configure the table so that it can have a fix number of rows (no add/remove actions) + the labels of the actions. |
61aea31 to
eb82ba3
Compare
|
@straku @jimjasson I've addressed your feedback by allowing consumers to control these actions: they can disable them and update the labels by leveraging the Edit config. By default, the table displays with delete/add actions and the labels are "Add item", "Remove item": {
id: 'productList',
label: 'Product List',
type: 'array',
children: [ /* ... */ ],
}Consumers can configure the labels as such: {
id: 'productList',
label: 'Product List',
type: 'array',
Edit: {
control: 'table',
actions: {
delete: "Remove product",
add: "Add product"
}
},
children: [ /* ... */ ],
}And consumers can also disable the actions (these renders a table without delete/add actions): {
id: 'productList',
label: 'Product List',
type: 'array',
Edit: {
control: 'table',
actions: {
delete: false,
add: false
}
},
children: [ /* ... */ ],
}We could be even more flexible: change the action icon, adding custom actions, etc. but I think that'd better be a follow-up, only when/if we need it. |
Makes sense!
This is very useful, thanks for addressing it! Overall, I like the decision to:
I tested the Fields stories and they all work as expected. However, the DataForm story is still not fully functional for me: (1) When I type in a single character in the product name field, it automatically loses focus: Screen.Capture.on.2025-09-30.at.16-46-37.mp4(2) The modal doesn't work correctly: Screen.Capture.on.2025-09-30.at.16-47-22.mp4 |
Alternative to #71782
What
This PR introduces the ability to have nested fields, by adding a new property
childrenin the Field API. It enables a few use cases (leverage thechildrenproperty to declare the type of the array elements, where we now only support strings), but the driving use case is to be able to handle dynamic list of data in DataForm:By leveraging the children as follows:
we can create experiences like this:
Screen.Recording.2025-09-23.at.12.10.59.mov
Why
We want to operate with dynamic list of data in DataForm.
Testing instructions
Open storybook (
npm install && npm run storybook:dev) and visit the stories: