[英]FlaskForm wtforms multiple input fields single submit
使用FlaskForm和SelectMultipleField,我創建了一個選擇表,允許對多個選擇進行排名:1、2、3,...。
為了將選擇內容放置在表格上的網格模式中,我使每一行都是SelectMultipleField的實例。
提交按鈕僅返回SelectMultipleField(狗)的第一個實例的值。
如何獲取Submit按鈕以在SelectMultipleField的所有實例中返回值?
這是我的表單模塊中的類:
class LPRForm(FlaskForm):
party = ['Dogs', 'Cats', 'Rabbits', 'Birds']
dog = [('', 'D. Duke'), ('', 'R. Rusty'), \
('', 'T. Tucker'), ('', 'R. Roger')]
cat = [('', 'S. Shadow'), ('', 'M. Misty'), \
('', 'P. Patch'), ('', 'P. Paws')]
rabbit = [('', ''), ('', 'C. Clover'), ('', ''), ('', '')]
bird = [('', 'P. Pikachu'), ('', 'S. Starburst'), \
('', ''), ('', 'F. Flighty')]
vote_dog = SelectMultipleField('District', choices=dog,
option_widget=widgets.TextInput() )
vote_cat = SelectMultipleField('District', choices=cat,
option_widget=widgets.TextInput() )
vote_rabbit = SelectMultipleField('District', choices=rabbit,
option_widget=widgets.TextInput() )
vote_bird = SelectMultipleField('District', choices=bird,
option_widget=widgets.TextInput() )
submit = SubmitField('Cast Ballot')
以下是html文件的相關說明:
<table style="width:100%" align="center">
<tr>
<td> </td>
{% for vote in form.vote_dog %}
{% if vote.label != '': %}
<td>{{ vote(size="2") }}</td> <td>{{ vote.label }}</td>
{% endif %}
{% endfor %}
</tr>
<tr>
<td> </td>
{% for vote in form.vote_cat %}
{% if vote.label != '': %}
<td>{{ vote(size="2") }}</td> <td>{{ vote.label }}</td>
{% endif %}
{% endfor %}
</tr>
<tr>
<td> </td>
{% for vote in form.vote_rabbit %}
{% if vote.label != '': %}
<td>{{ vote(size="2") }}</td> <td>{{ vote.label }}</td>
{% endif %}
{% endfor %}
</tr>
<tr>
<td> </td>
{% for vote in form.vote_bird %}
{% if vote.label != '': %}
<td>{{ vote(size="2") }}</td> <td>{{ vote.label }}</td>
{% endif %}
{% endfor %}
</tr>
</table>
</td>
</tr>
{{ form.submit }}
和視圖模塊:
@app.route('/lpr', methods=['GET', 'POST'])
def lpr():
form = LPRForm()
return render_template('lpr.html', title='Home', form=form)
我可以通過使用FormField來使它工作。 但是,文檔給出的默認分隔符為-
。 此外,我僅在使用時明確標識了separator='-'
.
作為分隔符,在調用該類時,它是否可以正常工作,甚至使用了separator='-'
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.