Hi guys. I've been practicing my coding skills by implementing what I've learned and built an application using Flask. Now in the application, I'm using the WTForms for user input, which uses a SelectMultipleField in a form. My problem is that, I can't seem to make the app POST all the items in the field when selected. It only sends the first item selected, no matter how many fields the user selects.
The Flask documentation says this about the data sent from this field type, but I don't see this behavior:
The data on the SelectMultipleField is stored as a list of objects, each of which is checked and coerced from the form input.
Here's a complete, minimal Flask app that illustrates this:
#!/usr/bin/env python
from flask import Flask, render_template_string, request
from wtforms import Form, SelectMultipleField
application = app = Flask('wsgi')
class LanguageForm(Form):
language = SelectMultipleField(u'Programming Language', choices=[('cpp', 'C++'), ('py', 'Python'), ('text', 'Plain Text')])
template_form = """
{% block content %}
<h1>Set Language</h1>
<form method="POST" action="/">
<div>{{ form.language.label }} {{ form.language(rows=3, multiple=True) }}</div>
<button type="submit" class="btn">Submit</button>
</form>
{% endblock %}
"""
completed_template = """
{% block content %}
<h1>Language Selected</h1>
<div>{{ language }}</div>
{% endblock %}
"""
@app.route('/', methods=['GET', 'POST'])
def index():
form = LanguageForm(request.form)