Reputation: 41
I can't see what I'm doing wrong in a FlaskForm. I'd like the email address to be optional.
Even if an entered email is valid, it does not pass validation if email is optional. It might be my imagination but I think this used to work fine. I did update all my requirements recently, did something change? I'm now using:
Flask==1.0.2
Flask-WTF==0.14.2
WTForms==2.2.1
example:
from wtforms import StringField
from wtforms.validators import DataRequired, Optional, Email
class ProfileForm2(FlaskForm):
"""
Form for user to add or edit profile. Email optional
"""
# this passes with valid email:
email_req =StringField('Email', validators=[DataRequired(), Email()])
# this never passes with same valid email
email = StringField('Email (optional)', validators=[Optional(), Email()])
Any suggestions?
Upvotes: 3
Views: 1400
Reputation: 41
My bad. There was a bug in my view function for the form. Not good for my very first Stackoverflow question. Sorry.
Upvotes: 1