我正在使用flask wtf表单构建表单。我有一个字段,用户可以在其中选择多个选项。如果他们想要的选择不在我的名单上。我想允许用户选择“其他”并通过文本字段指定他们的选项
我找不到办法在wtforms中这样做。我在谷歌上搜索过,似乎在任何地方都找不到答案。我所做的绝不是一个独特的场景,我会想象这是非常普遍的。所以我想我可能是想错了
question1_options = [('rice','rice'),('chips','chips'),('tuna','tuna'), ('other', 'other')]
question2_options = [('yes', 'yes'),('no', 'no')]
class MyForm(FlaskForm):
q1 = SelectMultipleField('favourite food?', choices=question1_options)
q2 = RadioField('do you like football', choices=question2_options)
我想要实现的目标:
将SelectMultipleField与StringField组合,以便在列表中没有相应选项时使用。用户可以选择其他并输入他们想要的内容
我找不到合并两个字段的方法
我认为它应该是两个始终可见的分离字段
或者,当您选择
other
时,它应该使用JavaScript
来显示StringField
我试图创建最小的工作代码
因为它使用
multiple select
,所以需要更复杂的JavaScript
代码与
addEventListener
相同,而不是onchange
相关问题 更多 >
编程相关推荐