3

I have a radio button group like this:

$options = array('2' => t('Active (2)'), '1' => t('Upcoming (1)'), '0' => t('Finished (0)'));
$form['active'] = array(
'#type' => 'radios',
'#title' => t('Update state:'),
'#default_value' => $default_entry->active,
'#options' => $options,
);

which works fine. However, based on a drop-down list of entries, it calls an ajax function which should update the selection:

foreach (array('name', 'test') as $item) {
$form[$item]['#value'] = $entry->$item;
}
foreach (array('active') as $item) {
???
}

Now, the "name" and "test" work as expected as they are text fields.... but the active radio button stays the same as it was (i.e. based on the '#default_value').

I have tried

$form[$item]['#value'] = $entry->$item;
$form[$item]['#default_value'] = $entry->$item;

but neither change which radio button is selected. Is there something I'm missing based on updating the "checked" attribute for that radio group?

Any help and/or points in the right direction much appreciated.

2
1

You would need to show more code (the form definition), I would recommend you to try:

unset($form['input'][$item]);

Right prior to calling:

$form[$item]['#default_value'] = $entry->$item;

Relative links: https://www.drupal.org/node/1082818#comment-5335080

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.