I need  use "Sequence of Mapping Widgets" with default values
but form render empty fields for sequence items, wen i press "add"
button

Default values from class Schema are correctly rendered
But textField1, integerField1, enabled1 from class someFields is empty


Here my example code:

resources.py

# -*- coding: utf8 -*-
import colander
import deform

class someFields(colander.Schema):
    textField = colander.SchemaNode(colander.String(),
            default="text")
    integerField = colander.SchemaNode(colander.Integer(),
                        default=0)
    enabled = colander.SchemaNode(colander.Bool(),
                    default='true')

class Fields(colander.SequenceSchema):
    fields = someFields()

class Schema(colander.Schema):
    textField1 = colander.SchemaNode(colander.String(),
            default="text1")
    integerField1 = colander.SchemaNode(colander.Integer(),
                        default=1)
    enabled1 = colander.SchemaNode(colander.Bool(),
                    default='true')
    fields = Fields()

views.py

from pyramid.view import view_config
from deform import Form
from deform import ValidationFailure
from pyramid.renderers import render_to_response
import resources

@view_config(route_name='home', renderer='templates/mytemplate.pt')
def my_view(request):
    return {'project':'deformtest'}

@view_config(renderer='cform.html',route_name='testform')
def renderForm(context,request):

    schema = resources.Schema()
    myform = Form(schema, buttons=('submit',))
    if 'submit' in request.POST: # detect that the submit button was
clicked
        controls = request.POST.items() # get the form controls
        try:
            appstruct = myform.validate(controls)  # call validate
            # the form submission succeeded, we have the data
            return render_to_response('cform_ok.html', {'data':
appstruct},request=request)
        except ValidationFailure, e: # catch the exception
            form=e.render() # re-render the form with an exception
    else:
        form = myform.render()
    return {'form': form}

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to