如何使用Flask-wtf动态更改表单的字段?

时间:2020-07-28 10:15:35

标签: jquery forms flask flask-wtforms

我目前正在从事涉及Flask-wtforms模块制作的登录表单的Flask初学者Web项目:

class LogInForm(FlaskForm):
    username = str_field('Username', validators=[DataRequired(), Length(min=2, max=20)])
    email = str_field('Email', validators=[DataRequired(), Email()])
    password = pwd_field('Password', validators=[DataRequired(), Length(min=6, max=20)])
    remember = BooleanField('Remember Me')
    submit = smt_field('Log In')

这是我的HTML中的表单片段:

    <form action="" method="post">
        {{ form.hidden_tag() }}
        <fieldset class="form-group">
            <legend>&nbspLog&nbspIn&nbsp</legend>
            <div class="form-group">
                {{ form.username(class="form-control form-control-md", placeholder="Username", autocomplete="off") }}
            </div>
            <div class="form-group">
                {{ form.password(class="form-control form-control-md", placeholder="Password") }}
            </div>
            <div class="form-check mb-3">
                {{ form.remember(class="form-check-input") }}
                {{ form.remember.label(class="form-check-label") }}
            </div>
            <button class="btn btn-outline-primary" type="submit">Log In</button>
        </fieldset>
    </form>
    <button type="button" class="btn btn-info btn-small mt-4">Use Email for Log In</button></small>

我要使最后一个按钮将form.username字段更改为form.email字段,以便用户可以在两者之间进行选择。我怎样才能做到这一点? jQuery是必需的吗?

0 个答案:

没有答案