I am working on code with a dependent dropdown list using the Form API for Drupal 7. The ajax request looks like its working (returning status 200) and I have know my options method is returning the correct array but it is still not changing the list... this is my code
$m1 = drupal_map_assoc(
array(
7,
)
);
$selected;
if(isset($form_state['values']['program'])){
$m2 = drupal_map_assoc(
array(
(int)$form_state['values']['program'],
)
);
$selected = key($m2);
}else{
$selected = key($m1);
}
$form['infocollect']['program'] = array(
'#type' => 'select',
'#title' => t('Program'),
'#required' => TRUE,
'#options' => array(
0 => t('Option 1'),
1 => t('Option 2'),
2 => t('Option 3'),
3 => t('Option 4'),
4 => t('Option 5'),
5 => t('Option 6'),
6 => t('Option 7'),
),
'#ajax' => array(
'callback' => 'deposit_campus_dropdown_callback',
'wrapper' => 'dropdown-campus-replace',
'method' =>'replaceWith',
),
'#prefix' => '<tr><td>',
'#suffix' => '</td></tr>',
);
$form['infocollect']['campus'] = array(
'#type' => 'select',
'#title' => t('Campus'),
'#required' => TRUE,
'#prefix' => '<tr><td><div id="dropdown-campus-replace">',
'#suffix' => '</div></td></tr></table><br />',
'#options' => _deposit_get_campus_options($selected),
);
......
function deposit_campus_dropdown_callback($form, $form_state) {
return $form['campus'];
}
function _deposit_get_campus_options($key='') {
dpm($key);
$options = array(
0 => drupal_map_assoc(
array(
t('Option 1'),
)
),
1 => drupal_map_assoc(
array(
t('Option 1'),
)
),
6 => drupal_map_assoc(
array(
t('Option 1'),
)
),
4 => drupal_map_assoc(
array(
t('Option 1'),
t('Option 2'),
t('Option 3'),
t('Option 4'),
)
),
5 => drupal_map_assoc(
array(
t('Option 1'),
t('Option 2'),
t('Option 3'),
t('Option 4'),
)
),
3 => drupal_map_assoc(
array(
t('Option 1'),
t('Option 2'),
t('Option 3'),
)
),
2 => drupal_map_assoc(
array(
t('Option 1'),
t('Option 2'),
t('Option 3'),
)
),
7 => drupal_map_assoc(
array(
t('none'),
)
),
);
if (isset($options[$key])) {
dpm($options[$key]);
return $options[$key];
}
else {
return array();
}
}
UPDATE: I have figured out that the problem is in the callback function deposit_campus_dropdown_callback , It is not finding $form['campus'] or $form['infocollect']['campus'] which is causing the ajax not to work, is there any way to get this fixed?