Selected yet disabled individual options from checkboxes widget don't persist through save

Created on 8 March 2022, almost 3 years ago
Updated 5 December 2023, about 1 year ago

Problem/Motivation

It is possible to programatically disable individual options on a checkboxes widget with the intention to show the selected value to users but disallow deselection, but if you do so the previously stored value will be removed despite having been show to the user as selected.

This is split out from #2911473: Selected yet disabled individual options from checkboxes element don't persist through save which addresses this more generally at the FAPI level and should be fixed first.

Steps to reproduce

  1. Add a field to article, as follows:
  • Field type: boolean
  • Field label: My Field
  • Save and continue
  • Set number of values to unlimited
  • Save field settings
  • Leave all settings, and click Save settings
  • Configure the Manage form display to use the widget "Checkboxes/radio buttons".
  • Add this line of code as the last line in book_form_node_form_alter
  • $form['field_my_field']['widget'][0]['#disabled'] = TRUE;
  • Enable the book module
  • Add an article, view the form -- see that the first option is disabled but selected
  • Submit the node form.
  • Edit the new article node -- see that the first option is disabled but NOT selected
  • Proposed resolution

    To be determined.

    Remaining tasks

    Diagnose.
    Fix.
    Add test.

    User interface changes

    None.

    API changes

    None.

    Data model changes

    None.

    🐛 Bug report
    Status

    Active

    Version

    11.0 🔥

    Component
    Field 

    Last updated 1 day ago

    Created by

    🇬🇧United Kingdom jonathanshaw Stroud, UK

    Live updates comments and jobs are added and updated live.
    • Needs tests

      The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

    Sign in to follow issues

    Comments & Activities

    Not all content is available!

    It's likely this issue predates Contrib.social: some issue and comment data are missing.

    Production build 0.71.5 2024