the default value doesn't show correctly for checkbox option widget in forms where the values are text. It always shows as selected.

this is because for a checkbox the default value is either True or False, but the form is setting the default value to
$items['default keys'][0], which is always true if you have 2 different texts for on and off.

this can be fixed by doing #default_value' => $items['default keys'][0] == $on_value

patch attached to do that.

CommentFileSizeAuthor
#6 optionwidgets.module.patch966 byteskenorb
checkbox_defaultvalue.patch562 bytesmoggy

Comments

binford2k’s picture

patch also works on 5.x with fuzz

john morahan’s picture

Version: 4.7.x-1.5 » 5.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

Problem still exists, patch still applies with a small offset and fixes it.

yched’s picture

Status: Reviewed & tested by the community » Fixed

Fixed - thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)
zmove’s picture

Status: Closed (fixed) » Active

Not fixed for me, I applied the patch and the checkbox continue to be checked by default. (even with uncheck default value in setting).

I use checkboxes on a nodeprodile node type, maybe it's the cause of the problem... don't know;

kenorb’s picture

Version: 5.x-1.x-dev » 5.x-1.6-1
Status: Active » Needs review
StatusFileSize
new966 bytes

Try attached patch. It should be working fine.

francewhoa’s picture

The following solution worked for me without any patching.

Into the help text in the 5.x-1.6 release:

For a 'Single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the Allowed values section. Note that the checkbox will be labeled with the label of the 'on' value.

So here's what you would do:

1) Add a Single on/off checkbox integer field.

2) Don't worry about changing the "Label" field since this does not does not have anything to do with what is displayed as the label.

3) Enter the following two values in the Allowed values list:
0|Do not display
1|Display

Now when you go to create content page for you content type you should have a checkbox with a "Display" label.

It works but it's not user friendly. It needs to be simplify.

Thanks to jsenich for this solution.

acrymble’s picture

this solved my problem without installing anything.

Thanks

karens’s picture

Status: Needs review » Closed (won't fix)

The D5 version is no longer being supported. Sorry.