Drupal 7에서는 #states
커스텀 jQuery 스크립트 대신 $ form을 사용할 수 있습니다 . 예:
$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'),
),
),
);
#states
여러 값 조건 에 사용하려는 경우의 예는 다음과 같습니다 .
$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),
),
),
);
자세한 내용과 예 는 form_example/form_example_states.inc
from examples 모듈 을 참조하십시오.