I have a Selectfield with some options and a blank default option with a custom validator
class Questions(FlaskForm):
question = SelectField('What"s up?', choices=[(None,"Please select an option"),(1,"Good"),(2,"Bad")],validators=[Required(message="Please select an option")])
def custom_validator(self,question):
if question == "None":
self.question.errors += (ValidationError("Please select an option"))
In my routes I call :
if form.validate_on_submit():
#do something
else:
#so something else
and my html looks like this
{{form.question.label}}
{{form.question.label}}
The custom validator seems to fire but the error message is not displayed as they normally are, e.g. when using a Required() validator on a StringField.
Am I missing something? Is there any good way of getting the tooltip error message for SelectFields?
Thanks.
question from:
https://stackoverflow.com/questions/65918531/wtforms-validation-error-message-for-selectfield 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…