Case:

create a cck field, type Integer, widget off/on.

use these options:
0|No
1|Yeah

Create the content type, and then create a node from that type.

If you check the box you just created and press save, in the database you will find 1 as a value.

However, if you view the node, the box will be not ticked.

There is a work-around: that is to use a text type instead of Integer. That works fine.

Comments

markus_petrux’s picture

Status: Active » Fixed

Nope. It also works with intergers. We have a few of these working here. Maybe it is something else that causes this to not work in your installation?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

greenskunk’s picture

I have this same problem but it was my fault for leaving one important part out. I've had it on one site for over a year and didn't figure out what was going on until a little while ago. I had a brain fart and was wondering why I didn't fill out the Allowed Values List.

When you create an integer field with the checkbox widget be sure to set your Allowed Values List.
Example:

  • 0|No
  • 1|Yes

Then just add a little function to your template.php file

/*
 * yes/no checkbox value
 * @param $element
 * @returns string Yes, No, Unknown
 */
function phptemplate_checkbox_yesno($element) {
  if (!empty($element)) {
  	if ($element['value'] == NULL) {
  		return "Unknown";
  	} elseif ($element['value'] == 0) {
  		return "No";
  	} else {
  		return "Yes";
  	}
  } else {
  	return "Problem";
  }
}
greenskunk’s picture

I'm using this on a site for a Select List with the field type of Integer.

A select list works better for if you have a field and you don't have a Yes or No answer to.

Example:

Use case: Field for showing whether a location is handicapped accessible and the client wants to show the field even if they don't have an value. If the handicapped accessible location wasn't touched during the entry of a node then the field will show as 'Unknown' using the above phptemplate_checkbox_yesno() function.

Field Type: Integer
Widget Type: Select List (this will allow you to select None, clearing the field of any value, during data entry into a node)

Allowed Values List:
0|No
1|Yes

Hope this helps.

eddy147’s picture

Thank you, GreenSkunk :)