wtforms

Flask WTForms: Difference between DataRequired and InputRequired

Flask WTForms: Difference between DataRequired and InputRequired Question: What is difference between DataRequired and InputRequired in wtforms.valiadators I have some fields in my signup form : username password password_repeat submit Should these fields use the DataRequired or InputRequired validator? Asked By: Ryan || Source Answers: Short Answer Unless you have a good reason you should …

Total answers: 1

Get None from a Fields data in instead of an empty string

Get None from a Fields data in instead of an empty string Question: I have this field in the WTForms form name = StringField(‘Name’, validators = [Optional(), Length(max = 100)]) When the field is submitted empty then form.name.data will, as expected, contain an empty string. Is there some way to make it return None in …

Total answers: 2

Flask WTForms always give false on validate_on_submit()

Flask WTForms always give false on validate_on_submit() Question: I have created a signup form using wtforms. I am using FormField in it so that I don’t have to repeat some of the elements of the form again. But whenever I click on the Submit button it always give me false on validate_on_submit method invocation. Not …

Total answers: 3

Flask-WTF uses input=submit instead of button type=submit

Flask-WTF uses input=submit instead of button type=submit Question: I would like Flask’s “SubmitField” to use <button type=”submit” title=”Save this form”><span>Save</span></button> Instead of: <input type=”submit” title=”Save this form” /> I am printing it out in templates: {{ field(class=css_class, title=field.description, **kwargs) }} I’m guessing that I have to somehow modify SubmitInput (the widget behind SubmitField), but I’m …

Total answers: 2

Not a Valid Choice for Dynamic Select Field WTFORMS

Not a Valid Choice for Dynamic Select Field WTFORMS Question: I currently am creating a dynamic select field using WTFORMS, however it never submits and fails the validation with the following error. Not a valid choice My Field is created like this: area = SelectField() and in the view, i am grabbing the options from …

Total answers: 4

How do you set a default value for a WTForms SelectField?

How do you set a default value for a WTForms SelectField? Question: When attempting to set the default value of a SelectField with WTForms, I pass in value to the ‘default’ parameter like so. class TestForm(Form): test_field = SelectField(“Test: “, choices=[(1, “Abc”), (2, “Def”)], default=2) I have also tried the following. class TestForm(Form): test_field = …

Total answers: 8

Flask-WTF – validate_on_submit() is never executed

Flask-WTF – validate_on_submit() is never executed Question: I’m using Flask-WTF: Here is my form: from flask.ext.wtf import Form, TextField class BookNewForm(Form): name = TextField(‘Name’) Here is the controller: @book.route(‘/book/new’, methods=[‘GET’, ‘POST’]) def customers_new(): form = BookNewForm() if form.is_submitted(): print “submitted” if form.validate(): print “valid” if form.validate_on_submit(): flash(“Successfully created a new book”) return redirect(url_for(‘.books_show’)) return render_template(‘views/books_new.html’, …

Total answers: 10

WTForms Can I add a placeholder attribute when I init a field?

WTForms Can I add a placeholder attribute when I init a field? Question: I want to add a placeholder attribute on to the field in WTForms. How can I do it? abc = TextField(‘abc’, validators=[Required(), Length(min=3, max=30)], placeholder=”test”) The above code is not valid How can I add a placeholder attribute with value? Asked By: …

Total answers: 4

How to make a field conditionally optional in WTForms?

How to make a field conditionally optional in WTForms? Question: My form validation is working nearly complete, I just have 2 cases I don’t know exactly how to solve: 1) The password field should be required of course but I also provide the possibility to log in with google or facebook account via OAuth and …

Total answers: 4

How to render my TextArea with WTForms?

How to render my TextArea with WTForms? Question: To render my textareafield with a specified number of columns and rows with WTForms, how do I set the number of columns and rows? I followed the instructions from this question but it didn’t work: How to specify rows and columns of a <textarea > tag using …

Total answers: 4