Skip to content

Commit

Permalink
Merge pull request #23 from toscawidgets/fix_checkbox
Browse files Browse the repository at this point in the history
Fix CheckBox validation to a proper boolean
  • Loading branch information
ralphbean committed Jun 12, 2013
2 parents 2fd15f9 + f8f8f93 commit ab00c2e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tw2/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class CheckBox(InputField):
type = "checkbox"
validator = twc.BoolValidator

def _validate(self, value, state=None):
# Since twc.BoolValidator returns None if no value is present
# (which is the common case if a HTML checkbox is not checked)
# we explicitly convert to bool again here
self.value = super(CheckBox, self)._validate(value, state)
return bool(self.value)

def prepare(self):
super(CheckBox, self).prepare()
checked = self.validator.to_python(self.value)
Expand Down

0 comments on commit ab00c2e

Please sign in to comment.