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

二次信任 提交于 2019-12-06 22:01:14

问题


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()

回答1:


Can you just prepend an empty pair to the list?

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



回答2:


If it's a QuerySelectField, you can add parameters like this:

allow_blank=True, blank_text=u'-- please choose --'


来源:https://stackoverflow.com/questions/5868718/wtforms-how-to-generate-blank-value-using-select-fields-with-dynamic-choice-val

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!