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.
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
Comment #1
abramo CreditAttribution: abramo commentedditto
Comment #2
abramo CreditAttribution: abramo commentedalso, 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.
Comment #3
pbarnett CreditAttribution: pbarnett commentedHi.
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.
Comment #4
abramo CreditAttribution: abramo commentedI 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"
Comment #5
abramo CreditAttribution: abramo commentedthe system ate the space so I try again:
Comment #6
lambert-1 CreditAttribution: lambert-1 commentedI 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.
Comment #7
abramo CreditAttribution: abramo commented.
- 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:
to get only the contents on the right side of the pipe (confusingly, this is also called a label)
or
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.:
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
.
Comment #8
denney CreditAttribution: denney commentedWhen 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.
Comment #9
denney CreditAttribution: denney commentedAs 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?)
Comment #10
gollyg CreditAttribution: gollyg commentedI 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.
Comment #11
abramo CreditAttribution: abramo commentedthe single box works for me.
Comment #12
ardas CreditAttribution: ardas commentedAnother trick is:
0
1|Checkbox title
for allowed values list.
Comment #13
abramo CreditAttribution: abramo commentednot a trick, really.
this is how the thing normally works . . . .
Comment #14
rar CreditAttribution: rar commentedI am getting the same error with Drupal-5.1 and CCK-5.x-1.5
Comment #15
wmostrey CreditAttribution: wmostrey commentedStill 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.
Comment #16
RobLoachJust a check-up saying that this problem still persists.
Comment #17
RobLoachSeems to work with the following values:
Single on/off checkbox, Multiple Values, and the following in Allowed Values...
0|No
1|Yes
Comment #18
jonahan CreditAttribution: jonahan commentedThanks 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.
Comment #19
dgtlmoon CreditAttribution: dgtlmoon commentedYeh 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!
Comment #20
abramo CreditAttribution: abramo commentedsame here
Comment #21
dgtlmoon CreditAttribution: dgtlmoon commentedI believe this issue is related to this issue about checkboxes failling
Comment #22
ray007 CreditAttribution: ray007 commentedsubscribing
Comment #23
yched CreditAttribution: yched commentedAs 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.
Comment #24
gstratis CreditAttribution: gstratis commentedThis 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.
Comment #25
kreynen CreditAttribution: kreynen commentedI'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.
Comment #26
yched CreditAttribution: yched commentedYep, the original reason for the way 'single on/off' works is probably something along those lines (Karen could probably confirm).
Comment #27
liquidcms CreditAttribution: liquidcms commentedand 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.
Comment #28
jmlane CreditAttribution: jmlane commentedYes, 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):
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/
Comment #29
jmlane CreditAttribution: jmlane commentedGiving this issue a more descriptive title for searches and what-not.
Comment #30
Miszel CreditAttribution: Miszel commentedHi 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
Comment #31
pingers CreditAttribution: pingers commentedJust 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
as mentioned in Allowed values meant that the checkboxes were never selected... this is a hack solution to unselect by default.
Comment #32
KarenS CreditAttribution: KarenS commentedThis is a duplicate of http://drupal.org/node/224391.
Comment #33
adampasz CreditAttribution: adampasz commentednode/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...
Comment #34
yched CreditAttribution: yched commentedThis has been fixed post RC4 - use latest 6.x-2.x-dev
Comment #35
adampasz CreditAttribution: adampasz commentedThanks. I have verified that this is fixed now.