Single checkbox default value cannot be changed

kaksisa - February 18, 2007 - 20:50
Project:Content Construction Kit (CCK)
Version:6.x-1.x-dev
Component:number.module
Category:bug report
Priority:critical
Assigned:Unassigned
Status:duplicate
Description

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?

#1

abramo - February 19, 2007 - 23:35

ditto

#2

abramo - February 20, 2007 - 00:31

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.

#3

pbarnett - February 21, 2007 - 12:04
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.

#4

abramo - February 22, 2007 - 20:08

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"

#5

abramo - February 22, 2007 - 20:10

the system ate the space so I try again:

  |
YES|YES

#6

lambert - March 5, 2007 - 19:42

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.

#7

abramo - March 5, 2007 - 20:37

.

- 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

.

#8

denney - March 7, 2007 - 14:34

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.

#9

denney - March 7, 2007 - 14:41

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

#10

gollyg - March 26, 2007 - 10:13

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.

#11

abramo - March 26, 2007 - 10:34

the single box works for me.

#12

ARDAS - April 10, 2007 - 17:54

Another trick is:

0
1|Checkbox title

for allowed values list.

#13

abramo - April 11, 2007 - 09:25

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

#14

rar - May 21, 2007 - 16:13

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

#15

wmostrey - May 24, 2007 - 12:19

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.

#16

Rob Loach - June 7, 2007 - 15:48
Version:4.7.x-1.3» 6.x-1.x-dev
Category:support request» bug report

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

#17

Rob Loach - June 7, 2007 - 16:09

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

#18

jonahan - July 10, 2007 - 18:22

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.

#19

dgtlmoon - July 13, 2007 - 06:50

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!

#20

abramo - July 14, 2007 - 07:54

same here

#21

dgtlmoon - July 16, 2007 - 01:48
Priority:normal» critical

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

#22

ray007 - July 25, 2007 - 19:48

subscribing

#23

yched - August 9, 2007 - 19:13
Status:active» by design

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.

#24

gstratis - August 10, 2007 - 12:43

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.

#25

kreynen - August 13, 2007 - 23:23

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.

#26

yched - August 13, 2007 - 23:37

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

#27

liquidcms - October 24, 2007 - 06:21

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.

#28

jmlane - March 12, 2008 - 19:04
Version:6.x-1.x-dev» 5.x-1.6-1
Status:by design» 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/

#29

jmlane - March 12, 2008 - 19:07
Title:Problems with checkboxes» Single checkbox default value cannot be changed

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

#30

Marcin Pajdzik - May 20, 2008 - 13:50

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

#31

pingers - May 30, 2008 - 07:58
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.

#32

KarenS - May 30, 2008 - 22:23
Status:active» duplicate

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

#33

adampasz - August 7, 2008 - 14:44

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

#34

yched - August 7, 2008 - 14:56

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

#35

adampasz - August 19, 2008 - 01:56

Thanks. I have verified that this is fixed now.

 
 

Drupal is a registered trademark of Dries Buytaert.