Skip to content

Instantly share code, notes, and snippets.

@nevergone
Created October 24, 2015 20:34
Show Gist options
  • Save nevergone/23f0a50bee01acc34ed2 to your computer and use it in GitHub Desktop.
Save nevergone/23f0a50bee01acc34ed2 to your computer and use it in GitHub Desktop.
/**
* Form callback
*/
function ajax_disable_test_form($form, &$form_state) {
$form['select'] = array(
'#type' => 'select',
'#required' => FALSE,
'#title' => t('Change me!'),
'#empty_option' => t('- Select -'),
'#options' => drupal_map_assoc(range(1, 3)),
'#prefix' => '<div id="select_box_wrapper">',
'#suffix' => '</div>',
);
$form['change'] = array(
'#type' => 'submit',
'#value' => t('Change!'),
'#ajax' => array(
'callback' => 'ajax_disable_test_form_submit_ajax',
'wrapper' => 'select_box_wrapper',
),
);
return $form;
}
/**
* Ajax callback
*/
function ajax_disable_test_form_submit_ajax($form, $form_state) {
$form['select']['#title'] = t('Changed!'); // It's work!
$form['select']['#disabled'] = TRUE; // It's not work!
return $form['select'];
}