Dan Jacob wrote:
Sorry, explanation required:
The code compares the "value" attribute of the widget with the input
value. As the input value is None, and you have not specified the
attribute value, this is also None. Therefore the "checked" attribute
is inserted. The Bool validator returns True or False, neither of which
equal None and therefore the attribute "checked" is missing. Therefore
always set the "value" attribute to an explicit value.
I know this is not clear or documented, and it would be better to have
a "value" argument in the constructor or somesuch.
Looks like it's working as it's supposed to, then. Given the following
widgets:
widgets.CheckBox(name="some_checkbox", labeltext="Some Checkbox",
validator=validators.Bool(), attrs={"value": 1}),
widgets.CheckBox(name="some_other_checkbox", labeltext="Some Other
Checkbox", validator=validators.Bool())
"some_checkbox" defaults to not checked, whereas "some_other_checkbox"
defaults to checked. "some_checkbox" holds a check (when you actually
check it) and "some_other_checkbox" won't hold a check. Specifying a
default (having my cake) and getting it to keep the value (eating it
too) would be great.
- jmj