今回テスト(セレクトボックス/チェックボックス/ラジオボタン)したソースは以下のとなります
function example_page($form, &$form_state){
// 1. Include CTools Dependent helper
ctools_include('dependent');
$form['select_set'] = array(
'#type' => 'fieldset',
'#title' => t('Selectbox Set'),
);
$form['select_set']['restrict_by'] = array (
'#title' => t('選択してください'),
'#type' => 'select',
'#options' => array (
'none'=>t('Select one'),
'trip'=>t('旅行'),
'month'=>t('カレンダー'),
),
'#default_value' => array('none'),
);
$form['select_set']['trips'] = array (
'#type' => 'select',
'#title' => t('旅行'),
'#options' => array (
'trip1' => t('地中海クルーズ'),
'trip2' => t('南極旅行'),
),
// セレクトが「旅行」の場合にこのエレメントが表示される
'#dependency' => array('edit-restrict-by' => array('trip')),
);
$form['select_set']['months'] = array (
'#type' => 'select',
'#title' => t('カレンダー'),
'#options' => array (
'1' => t('一月'),
'2' => t('二月'),
//...and so on
),
// セレクトが「カレンダー」の場合にこのエレメントが表示される
'#dependency' => array('edit-restrict-by' => array('month')),
);
$form['radio_set'] = array(
'#type' => 'fieldset',
'#title' => t('Selectbox Set'),
);
$form['radio_set']['restrict_by'] = array (
'#title' => t('選択してください'),
'#type' => 'radios',
'#options' => array (
'none'=>t('Select one'),
'trip'=>t('旅行'),
'month'=>t('カレンダー'),
),
'#default_value' => 'none',
);
$form['radio_set']['trips'] = array (
'#type' => 'select',
'#title' => t('旅行'),
'#options' => array (
'trip1' => t('地中海クルーズ'),
'trip2' => t('南極旅行'),
),
'#dependency' => array('radio:restrict_by' => array('trip')),
);
$form['radio_set']['months'] = array (
'#type' => 'select',
'#title' => t('カレンダー'),
'#options' => array (
'1' => t('一月'),
'2' => t('二月'),
//...and so on
),
'#dependency' => array('radio:restrict_by' => array('month')),
);
$form['Checkbox_set'] = array(
'#type' => 'fieldset',
'#title' => t('Checkbox Set'),
);
$form['Checkbox_set']['restrict_by'] = array (
'#title' => t('選択してください'),
'#type' => 'checkboxes',
'#options' => array (
'trip'=>t('旅行'),
'month'=>t('カレンダー'),
),
);
$form['Checkbox_set']['trips'] = array (
'#type' => 'select',
'#title' => t('旅行'),
'#options' => array (
'trip1' => t('地中海クルーズ'),
'trip2' => t('南極旅行'),
),
// チェックボックスのIDが変わったので注意が必要
'#dependency' => array('edit-restrict-by-trip--2' => array(true)),
);
$form['Checkbox_set']['months'] = array (
'#type' => 'select',
'#title' => t('カレンダー'),
'#options' => array (
'1' => t('一月'),
'2' => t('二月'),
//...and so on
),
'#dependency' => array('edit-restrict-by-month--2' => array(true)),
);
return $form;
}