Label not appear on Single on/off checkbox

CommentFileSizeAuthor
#1 cck_checkbox_label.patch596 bytesgstratis
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gstratis’s picture

FileSize
596 bytes

The issue is in line 114 of optionwidgets.module

          $form[$field['field_name']]['keys'] = array(
            '#type' => 'checkbox',
            '#title' => $options[$on_value],
            '#default_value' => $items['default keys'][0],
            '#return_value' => $on_value,
            '#description' => t($field['widget']['description']),
            '#required' => FALSE,
          );

I found that replacing with the code below resolves the problem.

          $form[$field['field_name']]['keys'] = array(
            '#type' => 'checkbox',
            '#title' => t($field['widget']['label']) ? t($field['widget']['label']) : $options[$on_value],
            '#default_value' => $items['default keys'][0],
            '#return_value' => $on_value,
            '#description' => t($field['widget']['description']),
            '#required' => FALSE,
          );
z.stolar’s picture

The correction does put the label in place, but the default value is not kept (I'm not sure it's the same issue)

gstratis’s picture

Not the same issue.

Regardless, I've tried to reproduce your problem and I can't, the default value appears just fine on new nodes and on editing existing ones. You should probably submit another issue with more details about how you setup your checkbox, and what the real behaviour is vs the expected one.

z.stolar’s picture

I found this solution as well:
http://drupal.org/node/149103

dgtlmoon’s picture

yched’s picture

Status: Active » Closed (works as designed)

Single On / Off checkboxes use the label of the 'on' value, defined in the 'allowed value' textarea.
For instance :

0
1|Check me !

I agree that is might look counter-intuitive, but I'm not sure of the reasons why it was implemented that way to begin withh, plus changing that now will break existing fields. I updated the help text to make that a little more obvious (1.6 release)

gstratis’s picture

This is not just counter-intuitive, it's plain confusing :) There are two fieldsets with form elements allowing a user to define the checkbox:

There exists a fieldset called "Widget Settings", in which the user fills in a "Label" text field. Intuitively, this should be the checkbox label. In fact, it's so intuitive that whoever created this form even used it as a label in the "Default Value" field, which shows a checkbox for the user to check or uncheck as default.

IT gets even worse when one considers what will happen if you have set the label using the "Allowed Values" label in the "Data settings" fieldset. You will have a checkbox with label A in your node form (where A is what you defined in the allowed values textarea) and you will have a label B in your "Default value" checkbox ( where B is what you defined in the "Label" text field ).

Someone please explain why the "Data Settings" fieldset, which contains all the data related settings, would have anything to do with the label of the checkbox? If there is a reason, I'm just not getting it.

KarenS’s picture

We don't need two threads with identical discussion, so keep further discussion in http://drupal.org/node/120377.