I've a form having a radios and 'select list with Ajax callback event'. When user changed selection from the select box, I tried to set the default_value for radio button. but it doesn't work.
In the function check()
I'm able to get the changed $id
value every time I change the select list, but the default_value not working. it's always checked to the value 1 ('Yes').
I've tried like following but not working.
/**
* Form.
*/
function myform($form, &$form_state) {
$current_items = array(1=> 'Yes',2 => 'No');
$form['current_items'] = array(
'#title' => t('Change value'),
'#type' => 'select',
'#options' => $current_items,
'#ajax' => array(
'callback' => 'ajax_change_callback',
'wrapper' => 'change-div',
),
);
$form['change_fieldset'] = array(
'#prefix' => '<div id="change-div">',
'#suffix' => '</div>',
'#type' => 'fieldset',
);
if (!empty($form_state['values']['current_items'])) {
$form['change_fieldset']['checkin_form'] = check($form_state['values']['current_items']);
}
else {
$form['change_fieldset']['checkin_form'] = check(1);
}
return $form;
}
/**
* Form callback.
*/
function ajax_change_callback($form, $form_state) {
return $form['change_fieldset'];
}
/**
* Callback Form.
*/
function check($id) {
$items = array(1 => 'Yes', 2 => 'No');
$form['checkin'] = array(
'#title' => $id,
'#type' => 'radios',
'#options' => $items,
'#default_value' => $id,
);
return $form;
}