0

I have a DateField that is part of a WTForm in Flask

from wtforms.fields.html5 import DateField

dob = DateField('Date of Birth', [InputRequired()], format='%m-%d-%Y')
    if form.is_submitted():
        print(form.dob.data)

HTML Template

{{ form.dob.label }}
<input type="date" id="DateofBirth" name="dob" class="form-control">

When the form is submitted it returns None. All other fields of the form work properly. Any suggestions?

1 Answers1

1

Solved it after a bit. Figured out I needed to remove the format parameter in the DateField object. The corrected field looks like this:

dob = DateField([InputRequired()])

When submitted the form.dob.data now outputs the correct date. This answer on another semi-unrelated question helped me out: https://stackoverflow.com/a/9519493/16549743. I guess HTML5 can't accept different formats as explained in that answer and passing the format parameter was messing things up.