I am having a problem when I use checkboxes in CCK.

I create a field of type Integer and select 'Single on/off checkbox' Widget. When I display the form the checkbox displays but without any label and if I try and check the default value checkbox the value is not saved and my checkbox always appears unchecked.

This doesn't seem like normal behavior? Has anyone else experienced this problem?

Comments

abramo’s picture

ditto

abramo’s picture

also, the N/A option of radio buttons, while it is available on the form does not function - i.e. when selected it reverts to one of the other existing values upon submission of the form. fields do display with one of the other values the system has reverted to, instead of N/A, - N/A would normally be expected to act as an "empty" field - i.e. not printing at all.

pbarnett’s picture

Version: 5.x-1.3 » 4.7.x-1.3

Hi.

I'm seeing the same problem with 4.7.x-1.3... the checkbox title is actually displaying the second value option rather than the title, and the asterisk denoting a required field does not appear for the checkbox either. See also http://drupal.org/node/115026

Pete.

abramo’s picture

I have configured the "Single on/off checkbox" as follows, and it works:

in "Allowed values list" do:
|
YES|YES

(the first "allowed value" above is: "space""pipe""space"

abramo’s picture

the system ate the space so I try again:

  | 
YES|YES
lambert-1’s picture

I just tried that with 5.1. At least YES appears after the checkbox (I couldn't get a label to appear otherwise). However, when I submit, the checked value doesn't stick.

abramo’s picture

.

- better leave the "default value" as "unchecked"
- after the pipe, in place of "YES" you may insert any text/image url/etc you wish
- you should be able to "submit" without issue - it works if everything else is properly configured
- I also do not get a label on the submission form - I use the help text appearing below the checkbox to label the field. this should be possible to rectify from within the module code, but I have not tried this yet.
- try printing with:

<?php print $node->field_myfield[0]['view'] ?>

to get only the contents on the right side of the pipe (confusingly, this is also called a label)
or

<?php print $node->content['field_myfield']['#value'] ?>

to get the label AND the label (good grief) meaning the actual label (name) of the field (in this case "myfield") and the label appearing on the right side of the pipe in "allowed".

if you want these two next to each other (inline) rather than one label under the other as is the default, then at Administer > Content Types > MyContentType > Display Fields > Label you have to specify (for your particular CCK field) "Inline"

you may keep only the "left label" without the "right label" if you specify "Hidden", or specify a transparent image as the label, ex.:

YES|<img src="/images/transparent.gif">

however, if you need to get rid of the ":" that is stuck automatically at the end of the "left label" you have to delete it from the theming code within the module itself.

these have worked for me in 5.1

best,
abramo

.

denney’s picture

When it comes to the checkbox default value and 5.x-1.4, I have the opposite problem. I cannot change the default value so it's always CHECKED!

It worked fine in, I think it was, 5.x-1.2 or 5.x-1.3, I can't remember.

denney’s picture

As a temporary workaround, create a "Check boxes/radio buttons" item and set the default value to "N/A".

Edit that item and change it to a "Single on/off checkbox" and save it. Your checkbox should then be unchecked by default.

Maybe the reverse of this would work for the issue creator? (eg. create the item and set the default value to something other than "N/A" and then change the item. The checkbox should be checked by default?)

gollyg’s picture

I have had success by changing the single checkbox to checkboxes, and then adding one default value. You need to be careful which cck type you are using - if your default values have text you need to be using a text box.

This stores the value and provides the correct label.

dont know why the single box does not work though, but in many ways it is redundant.

abramo’s picture

the single box works for me.

ardas’s picture

Another trick is:

0
1|Checkbox title

for allowed values list.

abramo’s picture

not a trick, really.
this is how the thing normally works . . . .

rar’s picture

I am having a problem when I use checkboxes in CCK.

I create a field of type Integer and select 'Single on/off checkbox' Widget. When I display the form the checkbox displays but without any label and if I try and check the default value checkbox the value is not saved and my checkbox always appears unchecked.

This doesn't seem like normal behavior? Has anyone else experienced this problem?

I am getting the same error with Drupal-5.1 and CCK-5.x-1.5

wmostrey’s picture

Still doesn't work, not for number.module or text.module. The only way for me to create a single checkbox is to create a "Check boxes/radio buttons", select "Allow multiple" so it's a checkbox and then just enter one value.

RobLoach’s picture

Version: 4.7.x-1.3 » 6.x-1.x-dev
Category: support » bug

Just a check-up saying that this problem still persists.

RobLoach’s picture

Seems to work with the following values:
Single on/off checkbox, Multiple Values, and the following in Allowed Values...
0|No
1|Yes

jonahan’s picture

Thanks Rob Loach - that works perfectly.

It just seems a little non-intuitive, like I never would have stumbled upon doing it that way. Maybe it can be made easier in the future.

dgtlmoon’s picture

Yeh this is a definately a very real UI bug

Look at all the people reporting it

Im not quite a newb to drupal and it took me a few hours of reading and bugreports to get this!

abramo’s picture

same here

dgtlmoon’s picture

Priority: Normal » Critical

I believe this issue is related to this issue about checkboxes failling

ray007’s picture

subscribing

yched’s picture

Status: Active » Closed (works as designed)

As was noted before in this thread, Single On / Off checkboxes use the label of the 'on' value, defined in the 'allowed value' textarea.

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 in the forthcoming 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.

kreynen’s picture

I'm not sure why the original developer did this, but I've done something similar to allow a form field to easily be changed between several "compatible" types. In CCK, as long as the datatype doesn't change you can modify an existing field to be a Text Field, Select list, Check boxes/radio buttons, or Single on/off checkbox without changing anything else.

Have a checkbox you'd like to expend to a select list with more values? No Problem. Just change the "Widget" and add more values. If there's anything unintuitive here, it's the use of the term widget. Everything else works consistently across all types of form fields.

Anyone who's every had to expand a checkbox or radio button to a select list in a CCK node type should really appreciate the way this was designed. The fact that Label doesn't show up in the form is a small annoyance compared to how elegantly form fields can be converted from one type to another.

yched’s picture

Yep, the original reason for the way 'single on/off' works is probably something along those lines (Karen could probably confirm).

liquidcms’s picture

and i think default value is still done wrong??? Pretty sure I posted this back in 4.7 and karen fixed it?

i have single checkbox with:

0|blah (doesnt matter - and i agree this is counter-intuitive)
1|Featured

and Default shows as "Featured" and is left unchecked

The issue is when the box is unchecked - the DB value stores NULL and it should store 0.

jmlane’s picture

Version: 6.x-1.x-dev » 5.x-1.6-1
Status: Closed (works as designed) » Active

Yes, the Default Value for single on/off checkbox is not working as expected.

I've set my checkbox up as required, with the following values, so my label displays correctly; that is not the issue (despite how unintuitive and odd this is):

off|One-time
on|Reoccuring

If I attempt to change the Default Value to an unchecked checkbox labeled "Reoccuring" and submit the field configuration page, when I go to create a new node with this field, "Reoccuring" checkbox is always checked.

Nothing I do seems to change this. I've tried enabling-disabling multiple values and the required options, but nothing changes.

Anyone know if there is an easy fix for this? Perhaps I am just "doing it wrong" as it took me quite some time to figure out how to get a label to display for my checkbox (5.x-1.6-1 doesn't have the updated help description which explains this).

Thanks for your help,

Jonathan M. Lane
OpenConcept Consulting Inc. http://www.openconcept.ca/

jmlane’s picture

Title: Problems with checkboxes » Single checkbox default value cannot be changed

Giving this issue a more descriptive title for searches and what-not.

Miszel’s picture

Hi jmlane

I have come accross the same problem. I want my checkbox to be off by default and can not find a way of doing that. Did you manage to solve this issue by any chance?

Thx

pingers’s picture

Version: 5.x-1.6-1 » 6.x-1.x-dev

Just tried the latest dev version and I'm still experiencing the same issue with checkboxes failing to save their default values.
I tried integer and text. Both exhibited same behaviour.

Edit content type -> uncheck default value -> save -> edit content type -> expand default value and it's selected

Edit content type -> uncheck default value -> save -> create new node -> checkbox is selected

EDIT:
Using values like

0|No
1|Yes

as mentioned in Allowed values meant that the checkboxes were never selected... this is a hack solution to unselect by default.

KarenS’s picture

Status: Active » Closed (duplicate)

This is a duplicate of http://drupal.org/node/224391.

adampasz’s picture

node/224391 says this is fixed, but this is not working for me using CCK 6.x-2.0-rc4 and Drupal 6.3. I can create a brand new on/off box, and once it's checked, there is no way to make it unchecked after submitting the form.

I am using these default values:
0|no flash
1|has flash

As a workaround: I changed the Widget Type to "checkboxes/radio buttons", and it works, but displays radio buttons instead of a checkbox.

The odd thing is, I know this used to work correctly about a month ago...

yched’s picture

This has been fixed post RC4 - use latest 6.x-2.x-dev

adampasz’s picture

Thanks. I have verified that this is fixed now.