Problem/Motivation
- Initial empty value - For unlimited cardinality, the current form element works like core fields where if the field has no default value, the element initializes with an empty value. This ultimately clutters the form unnecessarily and it is cleaner to allow user to choose when to add a value. We can also end up with unwanted values in array prop widgets that can result in undesirable SDC output without extra validation.
- Delete button - For unlimited cardinality, if the field is required and there is only 1 item the delete button is shown in a disabled state. For better UX, it would be better to only show delete button when item count is >1.
Proposed resolution
- Introduce an #add_empty property on the element with default value of FALSE. Adjust the initial $element_state['items_count'] to fallback to 0 when the field is NOT required or #add_empty is NOT TRUE.
- Add some logic to only show delete button when there is more than 1 item and the field is NOT required.
Issue fork custom_field-3588738
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
apmsooner commented