Search code examples
jquerypythonwtformsflask-wtforms

How can I dynamically add a WTForms TextField to a FieldList using jQuery?


I want to add or remove new WTForm input fields with button, using Jquery, just like here http://www.sanwebe.com/2013/03/addremove-input-fields-dynamically-with-jquery/comment-page-1 but using my form-fields.

my form:

class EditBook(Form):
title = TextField('title', validators = [Required()])
authors = FieldList(TextField())

problem is that I can't just append for example

$(InputsWrapper).append("{{form.authors(size=20)}}");

it just prints this text.


Solution

  • This answer is based on nsfyn55's explanations (first paragraph).

    I had a similar problem. The solution was to use: https://github.com/Rhyzz/repeatable-fields

    So, all you have to do is to look at the html snippet that is rendered by WTForms and use it as a 'template' in repeatable-fields plugin (see its docs for details)