-
Notifications
You must be signed in to change notification settings - Fork 4.5k
DataForm: Fix Edit for array
field type
#71000
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?
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. |
cc @chihsuan |
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.
Thanks for the fix! @oandregal The approach addresses the immediate issue well.
I have a few observations:
-
Default value mismatch: Should we also update line 20 for array field? e.g
const value = field.getValue( { item: data } ) ?? (field.type === 'array' ? [] : '');
-
Using
field.type
checks in controls creates coupling - Each new field type might require control modifications. While I'm fine with this approach, but if I remember correctly, we wanted to avoidfield.type
coupling in implementation. What are your thoughts on this? I'm not sure if it's easy to avoid this coupling. We would probably need to createmulti-select
control that fields can specify when elements are provided. Not blocking for this PR, just bring this up for discussion.
e110ef2
to
58261bc
Compare
Good catch, I fixed this as well.
I considered a One alternative that solves the two issues above would be to add a For now, I think this PR is fine to land: fixes the bug, doesn't introduce any new API, doesn't add new coupling between subsystems, and it's easy to migrate to another approach if we open up field type definition to 3rd parties. |
f8bdab0
to
58261bc
Compare
What?
When the
array
field type haselements
, render a multi-selection select control.Screen.Recording.2025-07-31.at.14.24.31.mov
Why?
It's returning an error because there's a mismatch between the control displayed for editing (
select
with single-selection) and the array nature of the field (multiple elements).How?
By making the
select
control use multi-selection when the field type is an array.Testing Instructions
npm install && npm run storybook:dev
, and visit the "DataViews > FieldTypes > Array" story.