Wtforms: How to generate blank value using select fields with dynamic choice values

Daniel Ozean picture Daniel Ozean · May 3, 2011 · Viewed 7.1k times · Source

I'm using Flask with WTForms (doc) on Google App Engine. What is the best way to generate an field with an empty value for a select field?

form.group_id.choices = [(g.key().id(), g.name) for g in Group.all().order('name')]

Is there something like "blank=True" for the form field?

myfield = wtf.SelectField()

Answer

Drew Sears picture Drew Sears · May 3, 2011

Can you just prepend an empty pair to the list?

form.group_id.choices.insert(0, ('', ''))