Hi,

When using multiple values on text fields, the default value is only applied to the first item.

I've managed to work around this issue by patching text.module - but not sure what impact this will have on other features. It seems to be working so far:

Before Workaround:

function text_widget(&$form, &$form_state, $field, $items, $delta = 0) {
  $element = array(
    '#type' => $field['widget']['type'],
    '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
  );
  return $element;
}

After Workaround:

function text_widget(&$form, &$form_state, $field, $items, $delta = 0) {
  $element = array(
    '#type' => $field['widget']['type'],
    '#default_value' => isset($items[0]) ? $items[0] : '',
  );
  return $element;
}

Comments

dmoore’s picture

Scratch that proposed solution - it seems to reset all the values once the default has been applied - but the following does seem to work:

function text_widget(&$form, &$form_state, $field, $items, $delta = 0) {
  $element = array(
    '#type' => $field['widget']['type'],
    '#default_value' => isset($items[$delta]) ? $items[$delta] : $items[0],
  );
  return $element;
}
karens’s picture

Status: Active » Closed (works as designed)

This is by design. Adding default values to other fields creates problems if the user doesn't notice them and they get stored as valid values that weren't desired.

We discussed this back and forth originally and decided that applying the default only to the initial value was the only 'safe' way to do this.