jquery - Getting data iterating over wtform fields -
i've got form, , number of dynamically adding fields,
class editbook(form): title = textfield('title', validators = [required()]) authors = fieldlist(textfield())
that's how append them
$('form').append('<input type="text" class="span4" id="authors-' + fieldcount +'" name="authors-' + fieldcount +'" placeholder="author ' + fieldcount +'">');
i want data theese inputs. how can iterate on them, using python?
(or how can send collected data jquery server? i'm new js , jquery)
guess inputs aren't connected authors fieldlist.
update
my inputs aren't connected editbook though append them it.
form.data solve rest of problem, when attach inputs form. (now keyerror, trying access form.data['authors-1'])
now try add single authors field copy later. renders invisible, unknown reason. in blank space should input, similar "author-1"
{{form.authors(class="span4", placeholder="author 1")}}
what should add code render field correctly?
the wtforms process_formdata
method pull these out of form submission , store them in data
attribute. below access code like. authors
list should stored in iterable can accessed authors
key.
from collections import namedtuple wtforms.validators import required wtforms import form wtforms import textfield wtforms import fieldlist webob.multidict import multidict class editbook(form): title = textfield('title', validators = [required()]) authors = fieldlist(textfield()) book = namedtuple('book', ['title', 'authors']) b1 = book('title1', ['author1', 'author2']) # drop them in dictionary data_in={'title':b1.title, 'authors':b1.authors} # build form , print form = editbook(data=multidict(data_in)) # lets data print form.data print form.data['title'] print form.data['authors']
Comments
Post a Comment