Closed (fixed)
Project:
Content Construction Kit (CCK)
Version:
6.x-1.x-dev
Component:
number.module
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
5 Sep 2006 at 04:10 UTC
Updated:
6 Dec 2006 at 14:46 UTC
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 commentedThe problem is the conditional if
Comment #2
mooffie commented(Oops, I accidentally changed the title.)
Comment #3
yched commentedSymmetrical effect : a non-required number field that's left empty stores a value of 0
Comment #4
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 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 commentedthis should be fixed in latest 4.7 and 5.0 branches
(please visit update.php after upgrading)
Comment #7
(not verified) commented