Drupal Association members fund grants that make connections all over the world.
I have a problem with setting the default value of my 'radios' button, dynamically. In my code, I have an addresses radios group stated like this:
$form['addresses'] = array( '#type' => 'radios', '#title' => '', '#options' => $addresses, isset($user->data['NewAddress']) ? $user->data['NewAddress'] : 0, );
This works, however, in my form, I have an ajax callback that lets the user add a new address and this address also gets added to the form once they save the address, via ajax. I want to now set the default value to this new address. The default_value, if I do a dd() of it, shows that it is set to the new address, however, it just doesn't get selected.
I have read somewhere, that the default_value only works the first time that a form is loaded. My situation is, the form loads once, then all the changes are being made via Ajax. I do a
$form_state['rebuild'] = true; after each new address is saved, however. So, basically, my question is, is there any way to get around this issue. How can we set the default_value each time a new address is entered via Ajax?
Any help would be greatly appreciated. Thanks.