Index: modules/field/field.form.inc ========================================================= --- modules/field/field.form.inc (revision 1.14) +++ modules/field/field.form.inc Mon Aug 17 12:24:12 PDT 2009 @@ -191,7 +191,10 @@ // Submit callback for disabled JavaScript. '#submit' => array('field_add_more_submit'), '#ajax' => array( - 'path' => 'field/js_add_more/' . $bundle_name_url_css . '/' . $field_name_url_css, + // @todo : Once 'callback' is accepted as the prefered implementation, + // remove the 'path' attribute. + //'path' => 'field/js_add_more/' . $bundle_name_url_css . '/' . $field_name_url_css, + 'callback' => 'field_add_more_js', 'wrapper' => $field_name_url_css . '-wrapper', 'method' => 'replace', 'effect' => 'fade', @@ -333,6 +336,37 @@ /** * Menu callback for AHAH addition of new empty widgets. */ +// @todo : Waiting on http://drupal.org/node/370537 to figure out validation +function field_add_more_js($form, $form_state) { + $field_name = $form_state['clicked_button']['#field_name']; + $bundle_name = $form_state['clicked_button']['#bundle']; + + // Retrieve field information. + $field = $form['#fields'][$field_name]['field']; + $instance = $form['#fields'][$field_name]['instance']; + $form_path = $form['#fields'][$field_name]['form_path']; + + // Fetch the form element that needs rendering. + $field_form = $form; + foreach ($form_path as $key) { + $field_form = $field_form[$key]; + } + + // Add a DIV around the new field to receive the AJAX effect. + $delta = max(element_children($field_form)); + $field_form[$delta]['#prefix'] = '
' . (isset($field_form[$delta]['#prefix']) ? $field_form[$delta]['#prefix'] : ''); + $field_form[$delta]['#suffix'] = (isset($field_form[$delta]['#suffix']) ? $field_form[$delta]['#suffix'] : '') . '
'; + // Prevent duplicate wrapper. + // @todo : why does it work when we don't unset, but doesn't work when we do unset? this needs investigation. + //unset($field_form['#prefix'], $field_form['#suffix']); + + // Rendering may produce status messages, so render first. + $output = drupal_render($field_form); + return theme('status_messages') . $output; +} + +// @todo : Remove this old implementation once the new one is accepted. +/* function field_add_more_js($bundle_name, $field_name) { // Arguments are coming from the url, so we translate back dashes. $field_name = str_replace('-', '_', $field_name); @@ -440,3 +474,4 @@ $commands[] = ajax_command_replace(NULL, $output); ajax_render($commands); } +*/