How to update a wtf-form state upon UI state change?

Viewed 582

Here is my flow so far working with WTF forms and updating their state upon user activity:

In my template.html I have:

<form action="{{ url_for('page') }}" method="POST">
    <select id="sel_id" name="name1" onchange="this.form.submit();">
    ...
    </select>
</form>

... And in views.py i got:

@app.route('/')
@app.route('/process', methods=['GET', 'POST'])
def process():
    form = NoNameForm()
    if request.method == 'POST':
        if 'name1' in request.form:                        
            form.colors = int(request.form['name1'])

Is this the correct way of working with WTF forms and updating variables such as form.colors in this case? I was wondering if I could simply update form.colors directly inside the "onchange" piece of js code.

1 Answers
Related