field_add_more_js

Versions
7
field_add_more_js($form, $form_state)

Ajax callback for addition of new empty widgets.

Code

modules/field/field.form.inc, line 364

<?php
function field_add_more_js($form, $form_state) {
  // Retrieve field information.
  $field_name = $form_state['clicked_button']['#field_name'];
  $field = $form['#fields'][$field_name]['field'];
  if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED) {
    ajax_render(array());
  }
  // Navigate to the right part of the form.
  $form_path = $form['#fields'][$field_name]['form_path'];
  $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.
  $langcode = $field_form['#language'];
  $delta = $field_form[$langcode]['#max_delta'];
  $field_form[$langcode][$delta]['#prefix'] = '<div class="ajax-new-content">' . (isset($field_form[$langcode][$delta]['#prefix']) ? $field_form[$langcode][$delta]['#prefix'] : '');
  $field_form[$langcode][$delta]['#suffix'] = (isset($field_form[$langcode][$delta]['#suffix']) ? $field_form[$langcode][$delta]['#suffix'] : '') . '</div>';

  return drupal_render($field_form);
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.