how to implement not-required DateField using Flask-WTF
You are looking for the Optional validator. start = DateField(‘Start Date’, format=”%m/%d/%Y”, validators=(validators.Optional(),))
You are looking for the Optional validator. start = DateField(‘Start Date’, format=”%m/%d/%Y”, validators=(validators.Optional(),))
The issue is that you’re always rendering the form with whatever data was passed in, even if that data validated and was handled. In addition, the browser stores the state of the last request, so if you refresh the page at this point the browser will re-submit the form. After handling a successful form request, … Read more
request.files is a dictionary where the keys are the names of the file fields. You can get the name of a WTForms field with my_form.my_field.name. So you can access the data uploaded from that field with request.files[my_form.my_field.name]. Rather than using the WTForms FileField, you can use the Flask-WTF FileField instead. It provides a data attribute … Read more
Short Answer Unless you have a good reason you should use InputRequired Why? Lets look at some notes from the docs/code for DataRequired() : Note there is a distinction between this and DataRequired in that InputRequired looks that form-input data was provided, and DataRequired looks at the post-coercion data. and NOTE this validator used to … Read more
The solution above have a validation bug, when one form cause a validation error, both forms display an error message. I change the order of if to solve this problem. First, define your multiple SubmitField with different names, like this: class Form1(Form): name = StringField(‘name’) submit1 = SubmitField(‘submit’) class Form2(Form): name = StringField(‘name’) submit2 = … Read more