Problem/Motivation
A Boolean or "List (text)" field configured as "Checkboxes/radio buttons", incorrectly renders the "N/A" radio button option in the Edit form. This is an optional field while unpublished, but required when published, and so should not have an "N/A" option.
Additionally, the field does not error as required-on-publish when empty and published.
Steps to reproduce
- Add a Boolean OR a List (text) field to a content type.
- Set the field as Required on Publish.
- Configure the widget in Manage form display as Checkboxes/radio buttons.
- Observe that the N/A option is available.
- Mark published and submit.
- Observe that the form submits successfully and did not throw a required-on-publish validation error.
Proposed resolution
- Ensure no "N/A" option is shown.
- Ensure validation error is shown.
Remaining tasks
- Determine whether to show N/A when conditionally not required on state change.
User interface changes
No "N/A" option is shown for Required on Publish Boolean nor List (text) Checkbox/radio field widgets.
When no option is chosen and the form submitted to be published, a validation error is shown.
Comments
Comment #2
jcandan commentedA workaround to hide the N/A option:
unset($form['field_my_custom_radio_buttons_list']['widget']['#options']['_none']);in ahook_form_alter()But, it fails to validate.
Comment #3
jcandan commentedComment #4
jcandan commentedThere is a caveat to this: technically, the radio field is optional until a user attempts to save as published.
I am debating whether to include a widget setting for Checkbox/radio buttons to enable/disable the N/A option.
Comment #5
jcandan commentedComment #6
jcandan commentedSeems this has some history in core.
Comment #7
jcandan commentedWe'll adopt a similar posture to the states handling introduced in #2951317-113: Radios element missing "required" attribute to show/hide N/A when not-required/required.
Comment #9
jcandan commentedComment #10
jcandan commented