Answer the question
In order to leave comments, you need to log in
How to add extra fields with Flask-wtf?
I want the user to be able to add or remove fields on the website. I know how to implement this directly with js, but what HTML attributes should I use to have flask-wtf write information to form.options .data ?
forms.py
class OptionsForm(FlaskForm):
option = StringField('options')
class CreatePollForm(FlaskForm):
title = StringField('Title', validators=[DataRequired()])
options = FieldList(FormField(OptionsForm), min_entries=2)
submit = SubmitField('Create')
<form action="{{ url_for('poll.new')}}" method="post" name="login">
{{form.hidden_tag()}}
<input type="text" name="title" />
<input type="text" name="options" id="options_0" />
{{ form.csrf_token }}
<p><input type="submit" value="Sign In"></p>
</form>
Answer the question
In order to leave comments, you need to log in
class CreatePollForm(FlaskForm):
title = StringField('Title', validators=[DataRequired()])
options = FieldList(StringField())
submit = SubmitField('Create')
<ul id="options">
<li>
<label for="options-0">Options-0</label>
<input id="options-0" name="options-0" type="text" value="">
</li>
<li>
<label for="options-1">
Options-1
</label>
<input id="options-1" name="options-1" type="text" value="">
</li>
<li>
<label for="options-2">Options-2</label>
<input id="options-2" name="options-2" type="text" value="">
</li>
...........
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question