python - How to do simple value check with error message in Deform/Colander -
i'm implementing simple 'tick agree terms , conditions box' in deform/colander.
so, want check box checked , have error message saying 'you must agree t&c'.
i understand can use:
colander.oneof([true])
to ensure box ticked. however, oneof not allow custom error message. correct way be?
use custom validator:
def t_and_c_validator(node, value): if not value: raise invalid(node, 'you must agree t&c') class myschema(colander.schema): t_and_c = colander.schemanode( colander.boolean(), description='terms , conditions', widget=deform.widget.checkboxwidget(), title='terms , conditions', validator=t_and_c_validator, )
Comments
Post a Comment