Answer the question
In order to leave comments, you need to log in
How to check the validity of one field out of two in wtform?
class MyForm(Form):
field1 = DecimalField('Сумма1', validators=[DataRequired()])
field2 = DecimalField('Cумма2', validators=[DataRequired()])
Answer the question
In order to leave comments, you need to log in
Solution in the forehead. Override the validate() method on MyForm and check if it's filled in. Something like:
class MyForm(Form):
field1 = DecimalField('Сумма1')
field2 = DecimalField('Cумма2')
def validate(self):
if not Form.validate(self):
return False
if field1.data:
if field2.data:
return True
return False
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question