简体   繁体   English

wtform selectfield 验证不要选择列表中的第一个

[英]wtform selectfield validation not to choose the first in the list

I've got two selectfield that the user should select an airport from a list, however I want the first option will be "make your choice" or something like that, and the user won't be able to choose (like a default choose)我有两个选择字段,用户应该从列表中选择一个机场,但是我希望第一个选项是“做出您的选择”或类似的东西,并且用户将无法选择(例如默认选择)

AIR_PORTS_LIST = [(0, 'Make Your Choice'), (1, 'praia'), (2, 'abidjan')]

class LoginForm(FlaskForm):
    airport_src = SelectField('AirPort Source', choices=AIR_PORTS_LIST, validators=[DataRequired()])
    airport_dst = SelectField('AirPort Destination', choices=AIR_PORTS_LIST, validators=[DataRequired()])

It is known as Placeholder and yes you can write in html like this:它被称为占位符,是的,您可以像这样用 html 编写:

{{ form.airport_src(placeholder='Make Your Choice') }}
{{ form.airport_dst(placeholder='Make Your Choice') }}

There is no need to write it in choices.没有必要写在选择中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM