I am using wtforms (version 2.3) and need to have a series of SelectField instances in my form. The choices for this repeated select field need to be dynamically supplied. I cannot figure out how to add the choices to the SelectField rather than the FieldList.
The code below reflects what I'm doing. I've confirmed that get_wtforms_people_for is returning a choice as a list of tuples appropriate for wtforms choices. However, form.people() in my output html renders without any choices.
class CompanySelectForm(Form):
company = SelectField('Company', validators=[validators.DataRequired()])
people = FieldList(SelectField(''), min_entries=1)
def get_form(company_name):
form = CompanySelectForm(data={'company': company_name})
if company_name:
# The following line runs, but does not produce any choices in output.
form.people.choices = get_wtforms_people_for(company_name)
return form