I have problem with drupal 7 and form ajax callback.
I have simple form with form select item and when i choose something ajax callback show item with form radios. Its actually works, but I get only radios item title and description but no options to choose.
function my_test_form($form, &$form_state) {
$form['places'] = array(
'#type' => 'select',
'#title' => t('Select twitter trends location'),
'#options' => array('1' => 'item 1', '2' => 'item 2'),
'#default_value' => 1,
'#description' => t('Select description'),
'#ajax' => array(
'callback' => 'my_test_form_callback',
'wrapper' => '.form-item.form-type-select.form-item-places',
'method' => 'append',
'effect' => 'fade',
),
);
return $form;
}
function my_test_form_callback($form, &$form_state) {
$form['trends'] = array(
'#type' => 'radios',
'#title' => t('Select'),
'#options' => array(0 => t('Closed'), 1 => t('Active')),
'#default_value' => 0,
'#description' => t('Radios description.'),
);
return $form['trends'];
}
result of print $form['trends'] -> dpm(drupal_render($form['trends']));
<div class="form-item form-type-radios">
<label>Select trend </label>
<div class="form-radios"></div>
<div class="description">Radios description.</div>
</div>
I would be happy for every advice. Thanks a lot.
The callback receives a built form. It's only responsible for returning the right part of the form.
my_test_form
is responsible for building the form for the first call and all the following AJAX calls. Simply put your condition inside this function.