I am trying to create a dynamic form (within a python Flask application) using WTForms.
WTForms includes a FieldList field for lists of fields. I'd like to use this to make a form where users can add or remove items, e.g. specify different phone numbers.
Here is an example of a WTF solution using Ajax with WTForms and related question. These clone an existing form, and hence only work if there is at least one instance of the form already. I would like to remove this constraint to also allow an initially empty form.
I would like to use a javascript form plugin called SheepIt to dynamically add/remove widgets which does allow this, using a "form template" in the html.
Question is how to replace custom html in the "form template" such as:
<input id="phoneForm_#index#_number"
name="user[phones][#index#][number]" type="text"
with a WTF form field such as:
{% for phone in form.phones %}
{{ phone.number }}
{% endfor %}
that allows the WTF goodies such as printing of form validation errors, etc. Problem here is I do not know if/where to place the above for loop when using a "template form" as done in SheepIt.