Searching for cascading ajax dropdown in this forum only gives me two discussions here and the other here
I have an almost similar issue only that the form select element I'm about to create cascades down in the 'taxonomy tree'. So each dropdown that was ajaxed will again be used to trigger another dropdown--in ajax...
Here is my sample module (trimmed down to relevant parts only):
function mainswitchboard($form,&$form_state){ $form = array('#prefix'=>'', '#suffix'=>''); $form['maincategory'] = array( '#title'=>'Firs Select', '#type'=>'select', '#options'=>_populate_dropdowns(), '#ajax'=>array( 'callback'=>'maincategory_callback', 'wrapper'=>'wrapper-div', 'method'=>'replaceWith' ) ); return $form; }
function maincategory_callback($form,$form_state){ $from_element_name = $form_state['triggering_element']['#name']; $triggerer = $from_element_name; $value = $form_state['values'][$triggerer]; drupal_set_message(time(). ' ' .$triggerer); $commands = array(); $arguments = array(); if(count(_populate_dropdowns($value))) { $form['subcat_for_'.$value] = array( '#title'=>'Subcat for '.$value, '#type'=>'select', '#options'=>_populate_dropdowns($value), '#attributes'=>array('id'=>'subcat_for_'.$value,'name'=>'subcat_for_'.$value), ); $arguments['ajax'] = array( 'subcat_for_'.$value=>array( 'event'=>'change', 'callback'=>'maincategory_callback', 'wrapper'=>'wrapper-div', 'method'=>'replaceWith', 'url'=>'/drupal7/system/ajax', ) ); $commands[] = ajax_command_settings($arguments,TRUE); } $commands[] = ajax_command_insert(NULL, drupal_render($form)); $commands[] = ajax_command_prepend(NULL, theme('status_messages')); return array('#type'=>'ajax','#commands'=>$commands); }
The above code seems to work the only problem is you the second dropdown no longer produce results (although a throbber is showing when you click the second dropdown..) The second dropdown does not seem to honor the arguments variable, hence, it does not seem to call the function in its callback...
I'm stuck new drupaler...
Thanks!