I have a problem where I have a few checkboxes in a form which have textfields associated to them. I want the textfields to be enabled when the individual checkboxes are checked. I have done this with states and it works just fine. However, I wanted to add a checkall checkbox for the user to select if they wanted to select all the checkboxes at once. I have done that with states as well.

The problem is, when the checkall checkbox is there, the textfield's enable and disable functionality gets messed up. It basically becomes inconsistent. For instance, if I select the checkall box and then deselect it, then, when I individually select a checkbox, the textfield doesn't enable, you have to deselect the individual checkbox and then select it again, for it to work. I have tested this in a number of modules and it does the same thing everywhere.

So I have basically concluded that this is a bug in Drupal and was hoping that it would get fixed soon as I would like to keep my jquery simple with the states. My code looks like this:

  //Add a checkall checkbox to select/deselect the individual checkboxes
  $form['checkall_demo']['checkall_checkbox'] = array(
    '#type' => 'checkbox',
    '#title' => t('Guarantee All Packages'),
  );

  //Add the individual checkbox 1, clicking the above checkall box should check this checkbox as well
  $form['checkall_demo']['checkall_fieldset']['checkbox_1'] = array(
    '#type' => 'checkbox',
    '#title' => t('Checkbox 1'),
    '#states' => array(
      'checked' => array(':input[name="checkall_demo[checkall_checkbox]"]' => array('checked' => TRUE)
      ),
    ),
  );
    
  //Add a textfield which will be enabled when the individual checkbox 1 is checked
  $form['checkall_demo']['checkall_fieldset']['textfield_1'] = array(
    '#type' => 'textfield',
    '#title' => t('Textfield 1'),
    '#default_value' => t('Hi'),
    '#states' => array(
      'enabled' => array(':input[name="checkall_demo[checkall_fieldset][checkbox_1]"]' => array('checked' => TRUE),
      ),
    ),
  );

I have also attached a zipped version of the problem, for anyone who wants to test it. Thanks.

CommentFileSizeAuthor
CheckAll Demo.zip1.31 KBshabana.navas

Comments

Version: 7.21 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.