I created a custom module followed by the dependent.inc todo comments.

Here is an radio selection at the beginning:

ctools_include('dependent');

function mymodule_form_alter(&$form, $form_state, $form_id) {

  if ($form_id == 'webform_client_form_myID'){

    $form['webform_client_form_myID']['#tree'] = TRUE;

    $form['depRadios'] = array (
      '#title' => 'Dependent on these radio buttons',
      '#type' => 'radios',
      '#options' => array (
        'r1' => 'Show fieldset',
        'r2' => 'Show textfield',
        'r3' => 'Show radios',
        'r4' => 'Show checkboxes',),
    );

..then add an fieldset to hide, when not r1 selected:

    $form['myFS'] = array (
      '#title' => 'My fieldset',
      '#type' => 'fieldset',
      '#process' => array('ctools_dependent_process'),
      '#dependency' => array('radio:depRadios' => array('r1')),
    );

1. Here comes the first problem, because nothing happens with My fieldset when i choose either r1-4 radio buttons.

Works perfectly if i create an textfield, then i select the r2 radio option: the hTextfield shown, otherwise hidden with this pure code:

    $form['myFS']['hTextfield'] = array(
      '#title' => 'Hide this textfield',
      '#type' => 'textfield',
      '#process' => array('ctools_dependent_process'),
      '#dependency' => array('radio:depRadios' => array('r2')),
    );

That's OK.

Now let's see how it's treats to hide the radios and checkboxes:

    $form['myFS']['hRadios'] = array (
      '#title' => 'Hide these radio buttons',
      '#type' => 'radios',
      '#options' => array (
        'hr1' => 'Radio 1',
        'hr2' => 'Radio 2',),
      '#process' => array('ctools_dependent_process'),
      '#dependency' => array('radio:depRadios' => array('r3')),
    );

    $form['myFS']['hCheckboxes'] = array (
      '#title' => 'Hide these checkboxes',
      '#type' => 'checkboxes',
      '#options' => array (
        'hc1' => 'Checkbox 1',
        'hc2' => 'Checkbox 2',),
      '#process' => array('ctools_dependent_process'),
      '#dependency' => array('radio:depRadios' => array('r4')),
    );
  }
}

2. It's so depressing, because both the hRadios's and the hCheckboxes's options doesn't shown in any case, but the #title still visible in every case.

I don't tried the previous versions of ctools, than I hope it's a bug only in 1.2 and just needs a JS patch.
Please highlight for Me if I miss something or I haven't used dependency correctly.

Comments

Benwick’s picture

Title: Dependent: fieldset don't hide, however radios and checkboxes don't shown » Dependent: Form's fieldset don't hide, however radios and checkboxes don't shown
Roi Danton’s picture

Your code is okay (e.g. try to change the form items into select fields). Dependent doesn't seem to support fieldset, radios and checkboxes as hideable items. Likely they have a different theme output comparing to select and textfield form items thus the JS in dependent.js has to be adjusted/expanded. Therefore the issue might be a feature request to support fieldsets, radios and checkboxes (and maybe more) as hideable items. However I haven't looked into the code yet so maybe it is already supported but doesn't work properly. So I leave it as a bug issue.

merlinofchaos’s picture

Fieldsets aren't supported because they don't run process hooks. Adding '#input' => TRUE to the fieldset works around that.

Checkboxes and radios aren't supported because Drupal doesn't provide an ID on the <div> around it. Adding a #prefix and a #suffix to provide the proper div works around that. This limitation with checkboxes is documented right there in dependent.inc -- but the fieldset workaround still needs to be added to the documentation.

merlinofchaos’s picture

I think the checkboxes documentation also needs to be cleaned up a little, probably with an example of how to add the #prefix and #suffix.

Roi Danton’s picture

Status: Active » Needs work
StatusFileSize
new3.43 KB

First patch (against 1.2) which adds your fieldset sentence, alters checkboxes description, adds an example for checkboxes and fixes two typos.

Though I'm not sure what expand_checkboxes in description means - the #process of checkboxes should be array('ctools_dependent_process', 'expand_checkboxes')? I have not tested the example so it is likely erroneous.

Roi Danton’s picture

StatusFileSize
new3.44 KB

Ignore patch above, please.

merlinofchaos’s picture

Status: Needs work » Needs review

Needs review is more appropriate since it'll get into the patch review queue that way.

merlinofchaos’s picture

Status: Needs review » Fixed

Thanks! Committed!

Status: Fixed » Closed (fixed)

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