I am using Ctools Dependency to make a fieldset hideable. This is part of my code:
$form['profile-status'] = array(
'#type' => 'radios',
'#title' => '',
'#options' => array(
'new' => t('Create a new profile.'),
'select' => t('Use an existing profile.'),
),
);
$form['select'] = array(
'#type' => 'select',
'#title' => t('Select a profile'),
'#options' => $options,
'#process' => array('ctools_dependent_process'),
'#dependency' => array('radio:profile-status' => array('select')),
);
$form['profile-properties'] = array(
'#type' => 'fieldset',
'#title' => t('View the profile'),
'#process' => array('ctools_dependent_process'),
'#dependency' => array('radio:profile-status' => array('select')),
'#input' => true,
);
In snippet above, There are two elements, one select and one fieldset. Both have #process and #dependency parameters and both point to one field for dependent value. Problem is elements like select or textfield can be hidden easily but it does not work for fieldset. In this support request page, CTools creator has mentioned that '#input' => true
is a work around. As you see I added it to code, but it does not work as well.
Do you have any suggestion?
I found my answer after reading the source of CTools dependent. Fieldset should change as this:
$form['profile-properties'] = array(
'#type' => 'fieldset',
'#title' => t('View the profile'),
'#process' => array('ctools_dependent_process'),
'#dependency' => array('radio:profile-status' => array('select')),
'#input' => true,
'#id' => 'my-fs-id',
'#prefix' => '<div id="my-fs-id-wrapper">',
'#suffix' => '</div>',
);
First an ID must be set for he fieldset. Then it must be wrapped in a DIV tag. ID of the DIV should be feildset's ID suffixed with '-wrapper'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With