I am using Pyramid with FormEncode to try to create and check a list of addresses. I am using pyramid_simpleform and look at this tutorial http://jimmyg.org/blog/2007/multiple-checkboxes-with-formencode.html and this previous Pylons FormEncode question with an array of form elements , but I still have some problems. My structure currently looks like this:
Scheme:
from formencode import Schema, validators, ForEach, NestedVariables class AddressSchema(Schema): allow_extra_fields = False addresses = validators.String(not_empty=True) class JobSchema(Schema): filter_extra_fields = True allow_extra_fields = True pre_validators = [NestedVariables()] job_name = validators.MinLength(5, not_empty=True) comments = validators.MinLength(5, not_empty=False) addresses = ForEach(AddressSchema())
Template:
${renderer.errorlist("addresses")} ${renderer.errorlist("job_name")} <p><label for="job_name">Job name: </label>${renderer.text("job_name", size=30)}</p> % for a in range(1, initial_number_of_address_fields): <p><label for="addresses-${a}">Address: </label>${renderer.textarea("addresses-" + str(a), cols=39, rows=6)}</p> % endfor ${renderer.submit("submit", "Submit")}
View:
@view_config(route_name='add_addresses', renderer="add_addresses.mak") def add_addresses(request): from myproject.forms import JobSchema from myproject.models import Job from formencode import htmlfill, variabledecode, ForEach initial_number_of_address_fields = 5 form = Form(request, schema=JobSchema(), variable_decode=False) renderer = FormRenderer(form)
I return the actual verification errors as follows: {'addresses': u'Missing value'} But correctly filled values ββalso lead to an error: The input must be dict-like (not a: u'dgfgfd)
If I change variable_decode to True (in the form variable setting), I no longer get any errors. I think I should use variableecode in some way, but I'm not sure how to do it. How to check these values?
source share