No Drupal 7, você pode usar $ form em #states
vez do script jQuery personalizado. Exemplo:
$form['student_type'] = array(
'#type' => 'radios',
'#options' => array(
'high_school' => t('High School'),
'undergraduate' => t('Undergraduate'),
'graduate' => t('Graduate'),
),
'#title' => t('What type of student are you?')
);
// High school information.
$form['high_school']['tests_taken'] = array(
'#type' => 'checkboxes',
'#options' => drupal_map_assoc(array(t('SAT'), t('ACT'))),
'#title' => t('What standardized tests did you take?'),
// This #states rule says that this checkboxes array will be visible only
// when $form['student_type'] is set to t('High School').
// It uses the jQuery selector :input[name=student_type] to choose the
// element which triggers the behavior, and then defines the "High School"
// value as the one that triggers visibility.
'#states' => array(
'visible' => array( // action to take.
':input[name="student_type"]' => array('value' => 'high_school'),
),
),
);
Aqui está um exemplo se você deseja usar #states
para a condição de vários valores:
$form['student_type'] = array(
'#type' => 'checkboxes',
'#options' => array(
'high_school' => t('High School'),
'undergraduate' => t('Undergraduate'),
'graduate' => t('Graduate'),
),
'#title' => t('What type of student are you?')
);
// High school information.
$form['high_school']['tests_taken'] = array(
'#type' => 'textfield',
'#title' => t('What standardized tests did you take?'),
'#states' => array(
'visible' => array( // action to take.
':input[name="student_type[high_school]"]' => array('checked' => TRUE),
':input[name="student_type[undergraduate]"]' => array('checked' => TRUE),
':input[name="student_type[graduate]"]' => array('checked' => FALSE),
),
),
);
Veja o form_example/form_example_states.inc
módulo from examples para mais detalhes e exemplos.