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.
With text fields that use the optionwidget of type 'onoff', there are currently two critical problems:
- values currently do not get saved at all after submitting a node add/edit form
- the label of the field doesn't get displayed on the node add/edit form
AFAICT, the cause of (1) is that the '#return_value' is not getting set to '1' (it's getting set to nothing) in the form definition for the widget, and that the submitted value is getting unnecessarily converted to an array. The cause of (2) is that the field's label is not getting assigned to '#title'.
Attached patch fixes these issues. Please review and commit if OK.
Comment | File | Size | Author |
---|---|---|---|
#1 | optionwidgets_fix_onoff_save_0.patch | 1.09 KB | Jaza |
optionwidgets_fix_onoff_save.patch | 1.14 KB | Jaza |
Comments
Comment #1
Jaza CreditAttribution: Jaza commentedOops - bad file paths in that patch. New patch attached.
Comment #2
Jaza CreditAttribution: Jaza commentedComment #3
z.stolar CreditAttribution: z.stolar commentedConfirmed. The patch has resolved the problem in my case.
One issue remains: I had to have a format of:
key|label
in the options area (e.g., I couldn't have just 'label')
Comment #4
ray007 CreditAttribution: ray007 commentedI can confirm that this patches fixes my problems with on-off checkboxes not getting saved correctly too. Patch should be applied to mainline if it doesn't cause any other problems.
Comment #5
ray007 CreditAttribution: ray007 commentedSeems I was a bit too optimistic, I'm again having troubles with the on-off checkbox.
Will use 2 radio buttons until this issue is resolved.
Comment #6
dgtlmoon CreditAttribution: dgtlmoon commentedI believe there are three issues at play here
- hook_widget for 'options_onoff' is not ensuring it only looks at the first set of key|value specified
Use the 'each' function to ensure we get the first (0) set of key|value's from the array not $vals[1]
- title field not wrapped in t() and not referencing the option value by key
- hook_widget for 'options_onoff' has nothing to check to see if it should be enabled by default or not
"$items['default keys'][0]" seems to always be set ?
this should be fixable, except for what to reference the default value as?
Comment #7
dgtlmoon CreditAttribution: dgtlmoon commenteddropping this back to active as there are still issues with figuring out what the default value should be referenced from ?
Comment #8
Christefano-oldaccount CreditAttribution: Christefano-oldaccount commentedThis patch seems to be working for me with no side effects.I'll leave the status unchanged, though, since I was already using the labeling method that z.stolar mentions in #3 and didn't test other methods.
Comment #9
tuti CreditAttribution: tuti commentedI'm using the latest version 1.6 (Aug 16) and I also have the problem with the on/off checkbox not working..? Has this patch not been implemented yet or do I have a new bug on my hands..?
Comment #10
jfall CreditAttribution: jfall commentedHow did you fix this? I'm using 5.x-1.6 and checkboxes work fine on the edit-node form.
However, I'm using the editable fields module, and it has the "unchecked boxes don't get submitted with the form" problem... http://drupal.org/node/236898
I'm trying to figure out how to fix it and wonder is the fix made to CCK might help me?
thanks.
Comment #11
incaic CreditAttribution: incaic commentedCheckboxes default value is incorrectly NULL in the database.
I thought KarenS fixed checkboxes here: http://drupal.org/node/224391
but noticed it was for version 6.x.
I just upgraded from 5.x-1.6 to the latest 5.x-1.7 and still have the same problem.
Is there a fix for this?
Comment #12
KarenS CreditAttribution: KarenS commentedThe D5 version is no longer being supported. Sorry.