'display a modal to the user only when form is valid in FlaskForm

I'm new to Flask, I'm looking for something like "If form.isvalid" then show a modal, similar to angular, but I don't find it. Here is what I'm trying to achive.

If the form is valid(i.e. if all the values are entered in the form) then show a modal to the user when he clicks on submit.

@home.route('/downloads/<product_name>', methods=['GET', 'POST'])
def downloads(product_name):
product = product_name
download_form = DownloadForm(product)
if download_form.is_submitted():
    if download_form.validate_on_submit():
        name = request.form['name']
        email = request.form['email']
        application = request.form['application']

        user_info = {'name': name,
                     'email': email,
                     'application': application}
        flash('Your form is submitted', "message")
    else:
        flash(f'{download_form.errors}.', 'error')
        logging.error(download_form.errors)

return render_template('downloads.html', form=download_form, product = product)

in the html I want to render a modal/dialog box to the user like below:

{% if form.isvalid %}
 //my modal html and javascript goes here
{% endif %}

Is this possible with FlaskWtf forms?



Solution 1:[1]

How about doing it with JavaScript?

form = document.getElementById("Form")

form.addEventListener("change" /* also could be submit */, function(){
var a = document.forms['Form'].reportValidity()
  alert(a)
/* Do something if true */
})

This seems to be following the validators set by WTForm.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Winmari Manzano