有没有办法在Flask WTForms中创建数据列表字段? [英] Is there a way to create a datalist field in Flask WTForms?
本文介绍了有没有办法在Flask WTForms中创建数据列表字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道使用Flask中的WTForms创建 datalist
字段的方法吗?
Does anyone know of a way to create a datalist
field using WTForms in Flask?
我知道如何创建 SelectField
,但是如果列表中没有该值,我需要允许用户输入自己的值.
I know how to create a SelectField
but I need to allow the user to enter their own value if it isn't in the list.
这就是我要做的事情 http://www.w3schools.com/tags/tag_datalist.asp
谢谢
推荐答案
您可以在视图中创建一个简单的StringField.
You create a simple StringField in your view.
autocomplete_input = StringField('autocomplete_input', validators=[DataRequired()])
在模板中,您调用字段并添加list参数(记住将条目传递到模板中):
In your template you call the field and add the list parameter (remember to pass the entries to your template):
{{form.autocomplete_input(list="id_datalist")}}
<datalist id="id_datalist">
{% for entry in entries %}
<option value={{ entry }}>
{% endfor %}
</datalist>
这篇关于有没有办法在Flask WTForms中创建数据列表字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文