How do I validate wtforms fields against one another?
You can use the form in your validation to get the value of other fields.
For example:
def validate_name(form, field):
if form.other_variable.data == 'checked' and len(field.data) > 10:
raise validation_error("say somgthing")
You can override validate
in your Form
...
class MyForm(Form):
select1 = SelectField('Select 1', ...)
select2 = SelectField('Select 2', ...)
select3 = SelectField('Select 3', ...)
def validate(self):
if not Form.validate(self):
return False
result = True
seen = set()
for field in [self.select1, self.select2, self.select3]:
if field.data in seen:
field.errors.append('Please select three distinct choices.')
result = False
else:
seen.add(field.data)
return result