Problem/Motivation
When zero is used as a valid choice in the "Available options" of an integer select list the edit form fails to find a default value and instead loads the empty option (-Select a value-). The "0" is stored correctly, the widget fails to load the value on the edit form.
Here's an example of options that fail:
KEY|VALUE
0|No idea - I do not know them
10|Uncertain
40|They have some experience
60|They are very experienced
80|They are a professional
Proposed resolution
In the select_or_other.field_widget.inc line 156 the#default_value is calculated by calling !empty() which returns false for a zero value. If we instead use isset() a zero value will be correctly handled.
Remaining tasks
For my use case with zero (0) values this works. Switching to isset() for strings seems to have no impact on the current behavior.
Testing with on a text field with the following available options:
KEY|VALUE
|empty
a|a
b|b
Resulted in the "empty" value being selected on edit no matter if it was "empty" (empty string) or null "- Select a value - " selected using either the existing !empty() or isset().
Attaching patch in a moment. Needs review.
Comment | File | Size | Author |
---|---|---|---|
#7 | zero-select-2024693-2.patch | 824 bytes | hhvardan |
#1 | zero-select-2024693-1.patch | 1.05 KB | stupiddingo |
Comments
Comment #1
stupiddingo CreditAttribution: stupiddingo commentedAttaching patch.
Comment #2
stupiddingo CreditAttribution: stupiddingo commentedAnd needs review.
Comment #3
haydeniv CreditAttribution: haydeniv commentedCommited b4203cb and rolled a new release 7.x-2.18
Thanks!
Comment #4
DamienMcKennaUpdated the status as the change was committed.
Comment #7
hhvardan CreditAttribution: hhvardan commentedThe issue still exists ... attaching another patch.