0

I know there are lots of tutorials on loads of sites (I have read most of them in the last few hours) but I still can not get the following code to work. Can anyone see what I am doing wrong?

The second select box does not update when I change a value in the first one and I don't get the blue spinning ajax circle next to the first select box when I make a change.

     $form['age_range'] = array(
      '#type'=>'select',
      '#title'=>'Age Range',
      '#options'=>$age_ranges,
      '#ajax'=>array(
          'event'=>'change',
          'callback'=>'childcare_observations_ajax_set_eyfs_category_list',
          'wrapper'=>'eyfs_category_wrapper',
          'method'=>'replace',
      )
    );

    $form['eyfs_category_wrapper'] = array('#prefix'=>'<div class="eyfs_category_wrapper">','#suffix'=>'</div>');

    $form['eyfs_category_wrapper']['eyfs_category'] = array(
      '#type'=>'select',
      '#title'=>'EYFS Category',
      '#options'=>array(1=>'one',2=>'Two'),
    );


    return $form;
}

function childcare_observations_ajax_set_eyfs_category_list($form,&$form_state){
    $eyfs_category_options = array();
    $eyfs_category_options[0] = "We just changed the list values";
    $eyfs_category_options[1] = "We also added a second option";
    $form['eyfs_category_wrapper']['eyfs_category'] = array(
        '#type'=>'select',
        '#title'=>'EYFS Category',
        '#options'=>$eyfs_category_options,
    );
    return $form['eyfs_category_wrapper'];
}
PrestonDocks
  • 4,851
  • 9
  • 47
  • 82
  • I have solved the problem in the end. Not sure what I did, but it seemed to be related to the menu item that was creating the form. After removing the menu item and refreshing the menu cache and then recreating with a new name and refreshing the cache again it all started to work. Strange! – PrestonDocks Nov 15 '13 at 02:07

1 Answers1

0

The wrapper should be the id of the element to replace. you have it as a class for eyfs_category_wrapper

plus I'm not sure if 'eyfs_category_wrapper' is a valid element, normally I use a field set, or just add a prefix and suffix to my target field.