ড্রুপাল 7 এ আপনি #states
কাস্টম jQuery স্ক্রিপ্টের পরিবর্তে $ ফর্ম ব্যবহার করতে পারেন । উদাহরণ:
$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
থেকে মডিউল উদাহরণ আরো বিস্তারিত জানার এবং উদাহরণ জন্য।