Я пытаюсь создать форму с динамическими полями (щелкните значок плюса, чтобы добавить дополнительные поля).
forms.py:
class ActionForm(Form):
key = SelectField("Type: ", coerce=int, choices=[(0, "Option 1"), (1, "Option 2"), (2, "Opeion 3")], default=0)
value = StringField('Value: ')
class EditForm(Form):
content = StringField("Content: ")
actions = FieldList(FormField(ActionForm))
status = RadioField("Status: ", coerce=int, choices=[(0, "Inactive"), (1, "Active")], default=1)
submit = SubmitField("Submit")
Просмотр шаблона (поля из ActionForm не отображаются):
<form method="POST">
{{ form.csrf_token }}
{{ form.actions.label }}
<div class="form-group input-group">
{% for action in form.actions %}
{% for field in action %}
{{ field() }}
{% endfor %}
{% endfor %}
</div>
{{ form.status.label }}{{ form.status }}
{{ form.submit() }}
</form>
Проблема:
В моей форме я просто вижу пустое место, где должны появиться поля ActionForm
.
Другими словами, я не могу перебирать form.actions
(чтобы показать SelectField () и StringField ()).
Что я делаю неправильно?
FieldList
ed - нет. Я просто пытаюсь поддерживать этот элемент Bootstrap с несколькими полями: bootsnipp.com/snippets/featured/ несколько полей. - person okoboko   schedule 06.06.2014