Reputation: 29
Hello Python Flask Experts:
I need help with rendering a form using wtf.quick_form
I am trying to publish a registration form having user name, password and a role field. User name and Password are straight forward text fields. Role is a select field.
My form looks like this
#------------------------------------------------------------------------------------------
class RegistrationForm(FlaskForm):
#------------------------------------------------------------------------------------------
yourName = StringField('Your Name', validators=[DataRequired()])
empId = StringField('Employee ID')
roleChoices = ('Manager', 'Stores', 'Sales', 'Engineer', 'QC', 'Vendor')
desiredRole = SelectField('Desired Role', choices=[(roleChoices, roleChoices)], default=1)
submit = SubmitField(_l('Register'))
And my Register.html looks like this
{% extends "base.html" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% block app_content %}
<h1>{{ _('Register') }}</h1>
<div class="row">
<div class="col-md-4">
{{ wtf.quick_form(form) }}
</div>
</div>
{% endblock %}
But, the output is not rendering the select field as a drop down.
It is showing just one item ('Manager', 'Stores', 'Sales', 'Engineer', 'QC', 'Vendor')
and selecting it as shown in the image below.
I consulted the WTForms documentation available at https://pythonhosted.org/Flask-Bootstrap/forms.html.
Looks like only text fields are rendered? Or have I made a any mistakes?
Upvotes: 0
Views: 523
Reputation: 29
Got the answer:
I was not forming the answer choices properly.
desiredRole = SelectField('Desired Role', choices=[(roleChoice, roleChoice) for roleChoice in roleChoices], default=1)
Now, the code output is rendering Select fields.
Upvotes: 2