RSS

(root)/drupal/7-fic : 539 : modules/field/field.form.inc

« back to all changes in this revision

Viewing changes to modules/field/field.form.inc

yched
2009-02-01 02:14:00
Revision ID: yched-20090201021400-0pbvjogksc01km31
Better fix for generic non-JS handling of 'add more' button.
See http://drupal.org/node/367006#comment-1231454 

Show diffs side-by-side

added added

removed removed

35
35
  // TODO : why do we need this ?
36
36
  $form['#cache'] = FALSE;
37
37
 
38
 
  // If the form is rebuilt (non-JS 'add more' button), we take the incoming
39
 
  // form values.
40
 
  // TODO : probably not the right fix. We'd need a field_attach_extract_form_values(),
41
 
  // and call it from field_add_more_submit().
42
 
  if (isset($form_state['rebuild']) && $form_state['rebuild'] && !empty($form_state['values'][$field['field_name']])) {
43
 
    $items = $form_state['values'][$field['field_name']];
44
 
    // If there was an AHAH add more button in this field, don't save it.
45
 
    unset($items[$field['field_name'] .'_add_more']);
46
 
  }
47
38
  // Populate widgets with default values if we're creating a new object.
48
 
  elseif (empty($items) && empty($id) && !empty($instance['default_value_function'])) {
 
39
  if (empty($items) && empty($id) && !empty($instance['default_value_function'])) {
49
40
    $items = array();
50
41
    $function = $instance['default_value_function'];
51
42
    if (drupal_function_exists($function)) {
284
275
 * entire form is rebuilt during the page reload.
285
276
 */
286
277
function field_add_more_submit($form, &$form_state) {
287
 
  // TODO : this is straight from poll_more_choices_submit().
288
 
  // not sure what we should do here...
289
 
  // Just setting $form_state['rebuild'] seems to do the trick ?
290
 
 
291
278
  // Set the form to rebuild and run submit handlers.
292
 
  //node_form_submit_build_node($form, $form_state);
293
 
  $form_state['rebuild'] = TRUE;
294
 
 
295
 
  $field_name = $form_state['clicked_button']['#field_name'];
296
 
 
297
 
  // Make the changes we want to the form state.
298
 
  if ($form_state['values'][$field_name][$field_name .'_add_more']) {
299
 
    $form_state['item_count'][$field_name] = count($form_state['values'][$field_name]);
 
279
  if (isset($form['#builder_function']) && drupal_function_exists($form['#builder_function'])) {
 
280
    $form['#builder_function']($form, $form_state);
 
281
 
 
282
    // Make the changes we want to the form state.
 
283
    $field_name = $form_state['clicked_button']['#field_name'];
 
284
    if ($form_state['values'][$field_name][$field_name .'_add_more']) {
 
285
      // TODO : use a 'field' namespace inside $form_state.
 
286
      $form_state['item_count'][$field_name] = count($form_state['values'][$field_name]);
 
287
    }
300
288
  }
301
289
}
302
290
 
404
392
  // We add a div around the new field to receive the ahah effect.
405
393
  $field_form[$delta]['#prefix'] = '<div class="ahah-new-field">'. (isset($field_form[$delta]['#prefix']) ? $field_form[$delta]['#prefix'] : '');
406
394
  $field_form[$delta]['#suffix'] = (isset($field_form[$delta]['#suffix']) ? $field_form[$delta]['#suffix'] : '') .'</div>';
 
395
  // TODO : this causes duplication of the wrapping divs
407
396
 
408
397
  // If a newly inserted widget contains AHAH behaviors, they normally won't
409
398
  // work because AHAH doesn't know about those - it just attaches to the exact

Loggerhead 1.17 is a web-based interface for Bazaar branches