AJAX Form Creation new checkbox not replacing wrapper div
Hello
I have been experimenting with the code in "Using the #ajax attribute for dynamic form building" after finding other Drupal tutorials hard to follow. I am finding that the initial form displays as it should. When I select one of the Operating System choices I see the "wait a minute" icon but when it stops rotating I do not see the checkbox. Examining with Firebug I can see the empty wrapper div when the form is first loaded but it does not get filled with the checkbox as I would expect.
I have cut out the other form examples to get down to just the ajax example. Here is the code I am using.
function bmc_dealer_dashboard_menu()
{
$items['dealer-dashboard'] = array(
'title' => 'Dealer Dashboard',
'page callback' => 'bmc_dealer_dashboard',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM
);
return $items;
}
function bmc_dealer_dashboard_form($form_state)
{
// Added AJAX callback.
$form['computer_stats']['os'] = array(
'#title' => t('Operating system'),
'#type' => 'select',
'#options' => drupal_map_assoc(array('', t('OSX'), t('Linux'), t('Windows'))),
'#ajax' => array(
'callback' => 'input_test_callback',
'wrapper' => 'input_os_verify_wrapper',
),
);
// Setting an empty element with a wrapper to be populated.
$form['computer_stats']['os_verify'] = array(
'#type' => 'markup',
'#prefix' => '
',
'#suffix' => '
',
);
// When submitted, check for value of OS, and populate os_verify.
if (isset($form_state['values']['os'])) { // Fixed this line, was throwing an error in the original video code.
$form['computer_stats']['os_verify']['#type'] = 'checkbox';
$form['computer_stats']['os_verify']['#title'] = t('Are you sure you are using @os?', array('@os' => $form_state['values']['os']));
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function bmc_dealer_dashboard()
{
return drupal_get_form('input_test_form');
}
function input_test_callback($form, $form_state) {
$form['computer_stats']['os_verify'];
}
Can anyone see what I might have broken or why the checkbox is not appearing where it should
Kind Regards
Richard