Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
mooffie CreditAttribution: mooffie commentedThe problem is the conditional if
Comment #2
mooffie CreditAttribution: mooffie commented(Oops, I accidentally changed the title.)
Comment #3
yched CreditAttribution: yched commentedSymmetrical effect : a non-required number field that's left empty stores a value of 0
Comment #4
KarenS CreditAttribution: KarenS commentedAnd 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.
Comment #5
yched CreditAttribution: yched commentedI'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.
Comment #6
yched CreditAttribution: yched commentedthis should be fixed in latest 4.7 and 5.0 branches
(please visit update.php after upgrading)
Comment #7
(not verified) CreditAttribution: commented