How to display additional fields if WTforms BooleanField checked (Flask python)?

Viewed 51

models.py

is_agent = db.Column(db.Boolean)

forms.py

is_agent = BooleanField('I am an Agent')
number = db.Column(db.String(10), nullable=True)
company = db.Column(db.String(20), nullable=True)

forms.py

<div class="form-check">
        {{ form.is_agent(class="form-check-input") }}
        {{ form.is_agent.label(class="form-check-label") }}
</div>
{% if form.is_agent.data == 'checked' %} # f checked, create these 2 additional fields for number/company{% endif %}

I am confused on how to bring all of these information together.

If the is_agent checkbox is checked by the user (it should be unchecked by default), then 2 additional fields of number/company should be displayed on the webpage.

I would appreciate any and all help!

0 Answers
Related