With text fields that use the optionwidget of type 'onoff', there are currently two critical problems:

  1. values currently do not get saved at all after submitting a node add/edit form
  2. 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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jaza’s picture

Oops - bad file paths in that patch. New patch attached.

Jaza’s picture

Assigned: Jaza » Unassigned
z.stolar’s picture

Confirmed. 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')

ray007’s picture

I 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.

ray007’s picture

Seems 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.

dgtlmoon’s picture

I 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]

         case 'options_onoff':
           // Display only the 'On' value of $options;
-          $vals = array_keys($options);
-          $on_value = $vals[1];
+          list($key, $val) = each($options);
+          $on_value = $val;
           $form[$field['field_name']]['keys'] = array(
             '#type' => 'checkbox',

- title field not wrapped in t() and not referencing the option value by key

-            '#title' => $options[$on_value],
+            '#title' => t($options[$key]),

- hook_widget for 'options_onoff' has nothing to check to see if it should be enabled by default or not

'#default_value' => $items['default keys'][0],

"$items['default keys'][0]" seems to always be set ?

this should be fixable, except for what to reference the default value as?

dgtlmoon’s picture

Status: Needs review » Postponed (maintainer needs more info)

dropping this back to active as there are still issues with figuring out what the default value should be referenced from ?

Christefano-oldaccount’s picture

This 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.

tuti’s picture

I'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..?

jfall’s picture

How 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.

incaic’s picture

Checkboxes 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?

KarenS’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

The D5 version is no longer being supported. Sorry.