Skip to content

Instantly share code, notes, and snippets.

@akhenakh
Last active December 16, 2015 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhenakh/5397538 to your computer and use it in GitHub Desktop.
Save akhenakh/5397538 to your computer and use it in GitHub Desktop.
Simple Bool field for WTForms, True for "set" False for "unset"
class RepeatForm(Form):
action = TextField('Action', validators=[Required()])
def validate_action(form, field):
if field.data == "set":
field.data = True
elif field.data == "unset":
field.data = False
else:
raise ValidationError("Invalid: should be set or unset.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment