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.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 654218_ctools_dependent_docs.patch | 3.44 KB | Roi Danton |
| #6 | 654218_ctools_dependent_docs.patch | 3.43 KB | Roi Danton |
Comments
Comment #1
Benwick commentedsources:
dependent.inc http://drupalcode.org/viewvc/drupal/contributions/modules/ctools/include...
dependent.js http://drupalcode.org/viewvc/drupal/contributions/modules/ctools/js/depe...
Comment #2
Benwick commentedComment #3
Roi Danton commentedYour 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.
Comment #4
merlinofchaos commentedFieldsets 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.Comment #5
merlinofchaos commentedI think the checkboxes documentation also needs to be cleaned up a little, probably with an example of how to add the #prefix and #suffix.
Comment #6
Roi Danton commentedFirst 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.Comment #7
Roi Danton commentedIgnore patch above, please.
Comment #8
merlinofchaos commentedNeeds review is more appropriate since it'll get into the patch review queue that way.
Comment #9
merlinofchaos commentedThanks! Committed!