Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293556

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

$
0
0

Problem/Motivation

When using the form element checkbox, it is possible to disable the element but having its value remain checked. This is used, for example, on the module overview page, where it is possible to check more modules, but impossible to uncheck already enabled modules:
screenshot_1.png

The same functionality is needed when using the form element "checkboxes". Currently, when an option of the checkboxes is disabled, it is saved as unchecked, even when it was set as default value as checked

screenshot_3.png

Steps to reproduce

Case 1

This case is covered by the test added in #7 and is fixed by the patch added in #26.

  • Configure a block to be only visible on articles
  • Add this hook to block.module
    function block_form_block_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
      $form['visibility']['node_type']['bundles']['article']['#disabled'] = TRUE;
    }
       
  • Go back to the block configuration form -- see that article is disabled but selected
  • Save the block configuration again, without any changes
  • Go back to the block configuration form -- see that article is disabled but NOT selected

Case 2

This case is not yet covered by tests and is not yet fixed.

  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
  2. Configure the Manage form display
    • to use the widget "Checkboxes/radio buttons".
  3. Add this line of code as the last line in book_form_node_form_alter
       $form['field_my_field']['widget'][0]['#disabled'] = TRUE;
       
  4. Enable the book module
  5. Add an article, view the form -- see that the first option is disabled but selected
  6. Submit the node form.
  7. Edit the new article node -- see that the first option is disabled but NOT selected

Proposed resolution

Ensure that disabled checkboxes values are not saved or their values persist.

Remaining tasks

  1. Manually test to confirm
  2. Write Tests to reproduce
  3. Fix bug

User interface changes

None

API changes

None

Data model changes

None


Viewing all articles
Browse latest Browse all 293556

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>