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

  1. Add a Boolean OR a List (text) field to a content type.
  2. Set the field as Required on Publish.
  3. Configure the widget in Manage form display as Checkboxes/radio buttons.
  4. Observe that the N/A option is available.
  5. Mark published and submit.
  6. 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.

Command icon 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

ronaldmulero created an issue. See original summary.

jcandan’s picture

Title: Hide "N/A" radio button field » Fix List (text) checkboxes/radio buttons
Version: 2.0.x-dev » 2.1.x-dev
Assigned: Unassigned » jcandan
Issue summary: View changes

A workaround to hide the N/A option:

unset($form['field_my_custom_radio_buttons_list']['widget']['#options']['_none']); in a hook_form_alter()

But, it fails to validate.

jcandan’s picture

Title: Fix List (text) checkboxes/radio buttons » Fix visible N/A option on radio buttons field widgets
Issue summary: View changes
jcandan’s picture

There 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.

jcandan’s picture

jcandan’s picture

Seems this has some history in core.

jcandan’s picture

Title: Fix visible N/A option on radio buttons field widgets » Fix radio field N/A option and error validation
Issue summary: View changes

We'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.

jcandan’s picture

Assigned: jcandan » Unassigned
Status: Active » Needs review
StatusFileSize
new16.63 KB
jcandan’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • jcandan committed 9ab91586 on 2.1.x
    feat: #3582502 Fix radio field N/A option and error validation
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.