0

I am working on the Flask tutorial from Miguel for input validation with WTForms. The forms.py is defined below:

from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import InputRequired

class LoginForm(FlaskForm):
    username = StringField('Username',validators=[InputRequired()])
    password = PasswordField('Password',validators=[InputRequired()])
    remember_me = BooleanField('Remember Me')
    submit = SubmitField('Sign In')

HTML file as below:

{% extends "base.html" %}
{% block content %}
    <h1>Sign In</h1>
    <form action="" method="post">
        {{ form.hidden_tag() }}
        <p>
            {{ form.username.label }}<br>
            {{ form.username(size=32) }}<br>
            {% for error in form.username.process_errors %}
            <span style="color:red;">[{{error}}]</span>
            {% endfor %}
        </p>
        <p>
            {{ form.password.label }}<br>
            {{ form.password(size=32) }}
            {% for error in form.password.process_errors %}
            <span style="color:red;">[{{error}}]</span>
            {% endfor %}
        </p>
        <p>{{ form.remember_me() }} {{ form.remember_me.label }}</p>
        <p>{{ form.submit() }}</p>
    </form>
{% endblock %}    

What I tried to achieve is to have the form report missing username and password input with error messages in red color. However, I got the following result when I click "submit"

enter image description here

I couldn't find where in the WTForms package produce the error message "Please fill out this field". I also checked the result HTML page, there is no Javascript code generated for this.

I have tried in both Opera and Edge and got the same error message. Is that something from Windows?

Thanks in advance for your help

chapter3
  • 914
  • 2
  • 12
  • 21
  • 1
    Would [this](https://stackoverflow.com/questions/50787904/how-to-override-the-html-default-please-fill-out-this-field-when-validation-fa) help you out? – Patrick Yoder Mar 20 '22 at 16:36
  • @PatrickYoder thanks mate! that's exactly the same problem. Don't know why the posts didn't show up in my Google search. Thanks again! – chapter3 Mar 21 '22 at 02:53

0 Answers0