Scenario:

You have a numeric field in your content-type, and this field is marked as "Multiple values". You enter some values into it, e.g. the three values 7, 0, 9. You save the node.

You now call up this node for editing, and you discover that the zero is missing. Only 7 and 9 appear in the form.

This is because of the textfield building code in 'number.module':

      if ($field['multiple']) {
        $form[$field['field_name']]['#type'] = 'fieldset';
        $form[$field['field_name']]['#title'] = t($field['widget']['label']);
        $delta = 0;
        foreach ($node_field as $data) {
HERE--->  if ($data['value']) {
            $form[$field['field_name']][$delta]['value'] = array(
              '#type' => 'textfield',
              '#title' => '',
              '#default_value' => $data['value'],
              '#required' => ($delta == 0) ? $field['required'] : FALSE,
              '#maxlength' => 11,
            );
            $delta++;
          }
        }

if problem is the conditional if ($data['value']). When the field's value is zero, the corresponding textfield is not generated.

Comments

mooffie’s picture

Title: "multiple" numeric zero fields not preserved upon edit » a tiny typo

if problem is the conditional if

The problem is the conditional if

mooffie’s picture

Title: a tiny typo » "multiple" numeric zero fields not preserved upon edit

(Oops, I accidentally changed the title.)

yched’s picture

Symmetrical effect : a non-required number field that's left empty stores a value of 0

KarenS’s picture

And fixing the second problem (storing 0 for non-required values) needs the patch at http://drupal.org/node/85929 (or something like it) to even make it possible for CCK to store NULL values. I am hoping to get some activity on that patch, which is holding up any effort to fix the handling of non-required values.

yched’s picture

Assigned: Unassigned » yched

I'm working on this - quite simple now that http://drupal.org/node/85929 got in, but I need to provide an update function for existing fields.

yched’s picture

Status: Active » Fixed

this should be fixed in latest 4.7 and 5.0 branches
(please visit update.php after upgrading)

Anonymous’s picture

Status: Fixed » Closed (fixed)