views:

32

answers:

2

This is a Drupal Forms question.

I am working on a UI that dynamically creates rows of 3 radio buttons based on a selected date. The problem I am having is that if I make some selections of the radio buttons and choose another date to get another set of radio buttons, the radios that were in the first list maintain their selected status and ignore the '#default_value' attribute.

What I want is when a new date is selected is that all the dynamically created radios to be unselected. The only way i can think of now is to create some unique key to use in the radios name for each set of radios.

A: 

Can you post the code you are using to make these radio buttons? Is all of this being done with AJAX or is the page refreshing?

Dylan West
A: 

here is part of the code that creates the rows of radio buttons. For each row in $result, I need to create a row of 4 radio buttons. I also try to set the #default_value of the radio buttons to what ever value was previous selected. This is fine for the initial submit, but if i make changes, and don't save, and want to get the original selected values, it maintains the currently selected values.

while ($my_data = db_fetch_object($result))
{   
  $form['opts'][$my_data->opt_id] = array(
    '#type' => 'radios',
    '#title' => t($my_data->option_name),
        '#options' => array(
         0 => 'N/A',
         1 => 'Yes', 
         2 => 'No',
         3 => 'Sometimes',
         ),
   );

   $form['opts'][$my_data->opt_id]['#default_value'] =  0;
   if($my_data->selected_opt_id != 0){
     $form['opts'][$my_data->opt_id]['#default_value'] =  $my_data->selected_opt_id;
   }
}

What I ended up doing was using JavaScript to set the default values every time the listing is requested. I think the issue was that "#default_value" is only good for controlling the initial view of the form, and isn't used on postback. Anyone can confirm?

PPC-Coder