diff --git includes/ajax.inc includes/ajax.inc index 7eab334..084f59c 100644 --- includes/ajax.inc +++ includes/ajax.inc @@ -200,6 +200,7 @@ function ajax_get_form() { */ function ajax_form_callback() { list($form, $form_state, $form_id, $form_build_id) = ajax_get_form(); + $triggering_element_name = $_POST['triggering_element']; // Build, validate and if possible, submit the form. drupal_process_form($form_id, $form, $form_state); @@ -208,9 +209,17 @@ function ajax_form_callback() { // drupal_process_form() set up. $form = drupal_rebuild_form($form_id, $form_state, $form_build_id); - // Get the callback function from the clicked button. - $ajax = $form_state['clicked_button']['#ajax']; - $callback = $ajax['callback']; + // Get the callback function from the clicked button. Processing a triggering element name + // like myfieldset[myfieldset2[myfielname]] or just myfieldname. + $triggering_element = $form; + foreach (preg_split('/[\[\]]+/',$triggering_element_name) as $element) { + if (!empty($triggering_element[$element])) { + $triggering_element = $triggering_element[$element]; + } + } + if (!empty($triggering_element['#ajax']['callback'])) { + $callback = $triggering_element['#ajax']['callback']; + } if (drupal_function_exists($callback)) { $html = $callback($form, $form_state); diff --git misc/ajax.js misc/ajax.js index 0804992..4d710d0 100644 --- misc/ajax.js +++ misc/ajax.js @@ -142,7 +142,12 @@ Drupal.ajax = function (base, element, element_settings) { // Bind the ajaxSubmit function to the element event. $(this.element).bind(element_settings.event, function () { + // Note that if #tree is FALSE in the form, and there are triggering elements of the + // same name, AJAX all falls apart. Use #tree = TRUE in a form with fieldsets. + triggering_element = element.name; if (ajax.form) { + ajax.form.append(''); + // If setClick is set, we must set this to ensure that the button's // value is passed. if (ajax.setClick) {