如何使用jQuery动态将WTForms TextField添加到FieldList? [英] How can I dynamically add a WTForms TextField to a FieldList using jQuery?
问题描述
我想使用Jquery使用按钮添加或删除新的WTForm输入字段,就像这里 http://www.sanwebe .com/2013/03/addremove-input-fields-dynamic-with-jquery/comment-page-1 但使用我的表单域.
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.
我的表格:
class EditBook(Form):
title = TextField('title', validators = [Required()])
authors = FieldList(TextField())
问题是我不能只添加
$(InputsWrapper).append("{{form.authors(size=20)}}");
它只是打印此文本.
推荐答案
此答案基于nsfyn55的解释(第一段).
This answer is based on nsfyn55's explanations (first paragraph).
我有类似的问题.解决方案是使用: https://github.com/Rhyzz/repeatable-fields
I had a similar problem. The solution was to use: https://github.com/Rhyzz/repeatable-fields
因此,您要做的就是查看WTForms呈现的html代码段并将其用作重复字段插件中的模板"(请参阅其
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)
这篇关于如何使用jQuery动态将WTForms TextField添加到FieldList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!