Remove the N/A option from the list of default values for a required boolean field

Created on 13 July 2024, 6 months ago
Updated 5 August 2024, 5 months ago

Problem/Motivation

In ๐Ÿ“Œ Drupal Usability Meeting 2024-07-12 Needs work (for the reference the attendees were @AaronMcHale, @benjifisher, @rkoller, @shaal, @simohell, and @worldlinemine) we've discussed ๐Ÿ› A required boolean field behaves differently depending on the widget Needs work which lead into this followup issue.
The problem is the following. Currently you have N/A, Off, and On as the available default value options. If the boolean field is set to required, either On or Off have to be the option of choice, N/A is not a valid option. But if you select N/A as the default value anyway and save the field settings you will notice when you reopen the field settings that the Set default value checkbox got unticked and no default value option is selected anymore. And if you take a look at the configuration for the boolean field you will also notice no matter if the Set default value checkbox is checked without a default value option or with N/A selected instead, default_value: { } remains empty after the field settings are saved.

Steps to reproduce

  • Add a boolean field to for example the article content type (/admin/structure/types/manage/article/fields)
  • On the field settings page make it a required field.
  • On admin/structure/types/manage/article/form-display set the boolean form display widget to Check boxes/radio buttons and save.
  • Go back to the field settings of the boolean field.
  • Check the Set default value button and select the N/A option and hit save
  • Go another time into the field settings of the boolean field

=> You will notice Set default value is unticked and no option is selected.

Proposed resolution

If the Required field of a boolean field is checked the N/A option should be removed from the list of available options since it has no purpose nor function except the potential to confuse the user. The listed default values should only be Off and On.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Fieldย  โ†’

Last updated 2 days ago

Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany rkoller Nรผrnberg, Germany

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @rkoller
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany rkoller Nรผrnberg, Germany
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany rkoller Nรผrnberg, Germany
  • First commit to issue fork.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia annmarysruthy

    @rkoller why do we need N/A in the set default value even when field is not required. When field is not required and and on clicking set default value , we can see option N/A . If I select N/A as default value and on saving, no default value gets saved. On editing the form again, set default value is left unchecked. The issue you mentioned occurs irrespective of whether the field is required or not

    Can we remove the N/A option from set default value for both required and not required fields and keep N/A in form display only when field is not required. That is if there is a boolean field 'field1' which is not required, on adding article content type field1 will have N/A option but on editing field field1, the set default value will not have N/A. if field1 is required, then both places wont be having N/A.

    Proposed Solution:

    Remove N/A from the options in set default value irrespective of whether the field is required or not.

  • First commit to issue fork.
  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia arunkumark Coimbatore

    Created MR to exclude the N/A or Empty option from the Boolean fields.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prem suthar Ahemdabad- Gujrat , Jodhpur - Rajsthan

    @ararunkumark

    I have attached a screenshot showing the behaviour of the form field with required and non-required values. When the field is required, the "N/A" option should be hidden. However, if the field is changed back to non-required, the "N/A" option should be shown again.

    With the Required Field is Working Fine as of now.

    Thanks.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia arunkumark Coimbatore

    @Prem Suthar

    The solution implemented based on the Proposed resolution and #5 ๐Ÿ“Œ Remove the N/A option from the list of default values for a required boolean field Needs review . There are 2 types of Field Types using the form display radios.

    Type 1. Listing Text/Integer/Float (1 value in storage )
    In this case, we have to choose Checkbox/Radio in the Form display. If the field allows 1 value on the storage, the field will render as Radios. The testing you did will work on this scenario.
    Type 2. Boolean
    But in Boolean type always 2 values TRUE or FALSE (i.e 1 or 0). In this case, we should not show the N/A option either required or not required.

    Note: The field type 1 will accept multiple values, the Form field is rendered as a checkbox.

  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    What about the people who have that option currently selected. Believe will need upgrade path of some kind with test coverage of that update.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia arunkumark Coimbatore

    @smustgrave

    If any user selected N/A or kept unselected there is no entry in the Database. Also, if the user edits the same entity it remains unselect of N/A. So, the N/A option is only shown in Form, there is no logic in data save.

    Selected N/A:

    Edited the same node:

    So, there is no impact in existing users who selected N/A

Production build 0.71.5 2024