6

this is a submit button code of a wtform:

{{ form.submit(class="w-50 btn btn-primary btn-sm submit-btn") }}

I am thinking of adding a class to it when it's clicked? i know a way of showing errors in wtform+jinja2 by adding class like this:

{% if reg_form.confirm_password.errors %}
   {{ reg_form.confirm_password(class="form-control form-control-sm is-invalid") }}
          <div class="invalid-feedback">
             {% for error in reg_form.confirm_password.errors %}
                <span>{{ error }}</span>
             {% endfor %}
          </div>
   {% else %}
       {{ reg_form.confirm_password(class="form-control form-control-sm")}}
   {% endif %}

i looked at the docs of submitField but I cannot see a way of disabling it. https://wtforms.readthedocs.io/en/stable/fields.html

gpbaculio
  • 5,693
  • 13
  • 60
  • 102
  • Possible duplicate of [Python Flask WTForms: How can I disable a field dynamically in a view?](https://stackoverflow.com/questions/16424374/python-flask-wtforms-how-can-i-disable-a-field-dynamically-in-a-view) – noslenkwah Sep 20 '18 at 12:53
  • Do you want to disable before clicking or after clicking? – simanacci Sep 25 '18 at 17:50

1 Answers1

0

You can do it directly during the definition of your form as:

# forms.py

class MyForm(FlaskForm):
    # ...
    submit = SubmitField("Submit", render_kw={"disabled": "disabled"})

# Then simply render your form
# index.html

{{ form.submit() }}

Or, you can do it from the templates as:

<!-- index.html -->


{{ form.submit.render_kw={"disabled": "disabled"} }}

<!-- OR -->

{{ form.submit(disabled=True) }}
Gitau Harrison
  • 3,179
  • 1
  • 19
  • 23