By knalstaaf on
How can I create a simple on/off checkbox in a content type in D7?
Currently I've got it configured as follows:
- Field type: List (integer)
- Values:
0|No
1|Yes - Number of values: 1 (tried "unlimited" as well)
It always shows both the values, while only "Yes" should be displayed.
When I only use 1 key, my Views Filter Criteria notice: No valid values found on filter: [my fieldname].
None of the documentation I've found works (mostly for D6). Personally I think this should be documented in the field description, for it's so frequently used.
Comments
Solution
I've got it working after all with the following configuration:
0|Yes
Concerning the No valid values found error in Views: make sure this filter criterion (on/off checkbox) is only applied on the display it should be applied on. Eventhough I remember setting it "only for this display" it did apply it on all displays. So check your other displays if this occurs...
Thanks knalstaaf, this saves
Thanks knalstaaf, this saves me plenty of time searching for the solution
For completeness I would add the widget type. (And a "kniesoor" like me, would use "1" as the key value for "Yes")
Resulting in:
- Field type: List (integer) & Widget: Check boxes/radio buttons
- Values:
1|Yes
- Number of values: unlimited
Exactly
I'm a bit of a little Pete Precise as well (bless our English), so I'm using "1" too from now on.
Concerning the No valid values found on filter: [my fieldname]-notice, if the problem persists, enable the master display in the settings of Views, and turn off the obsolete field in the master display of your View.
Not working for me
I'm trying to create a checkbox, but it's still showing up as a Select List on the product (add to cart) page. And it has a label of "Select a product" with two products listed. The functionality works, but the label is incorrect and it's not displaying a checkbox. It does show a checkbox on the admin pages when I maintain my products. Any ideas?
Update: It displays a single radio button if I change the Number of Values setting to 1. But no checkbox with Unlimited selected.
Select list?
Make sure that your field isn't defined as a "select list" in your Manage Fields tab. It should be "radio/checkboxes" or something.
There should only be one value in it (eg "1|Yes, send me the catalogue as well"), and the Number of values should be set to "unlimited".
Thanks
Thanks for the response. I had it setup just like you described (radio/checkboxes, 1|Yes, unlimited), but I couldn't get it to work. For now, I just changed it to a Select List with Yes and No options. I may experiment with it later. Thanks again.
Content type?
Are we talking about a regular content type or a webform?
Regular
Just a regular content type.
Unchecked as default value when the field is mandatory?
Does anyone know how to have an unchecked checkbox as default value, when the field is marked as mandatory?
Good question. I am
Good question. I am interested too.
Any luck with that, I need it
Any luck with that, I need it as well
Any news
on a solution?
Single checkbox, required, but off by default
I'm wondering too: http://drupal.org/node/1143516#comment-6375992
Any progress here?
The answer...
The answer is here... http://drupal.org/node/1143516#comment-6637208
It's never too late to have a happy childhood. ;-)
Try boolean
Add a new field:
Type: boolean
Widget: Single on/off checkbox
Label: "I agree to the terms and conditions"
Check required
Help text: Please check to agree with our Terms and Conditions
Check Use field label instead of the "On value" as label
Selwyn Polit
https://www.drupalatyourfingertips.com/
works good
works good
It works.. Awesome!
It works.. Awesome!
VIews No Like
This is how I set the thing up. But the problem is Views doesn't like it and I get the error 'No valid values found on filter' [...]
this answer should show up as
this answer should show up as the first search result in google as far as single checkbox required field in Drupal 7 content type