-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed rendering of sequence item "default values" in SequenceWidget #79
Conversation
Another simple code example: # -*- coding: utf8 -*- import colander import deform import urllib class seq(colander.SequenceSchema): field = colander.SchemaNode(colander.Bool(), default='true', ) class schema(colander.Schema): items = seq() print "Schema test:" sch=schema() print sch['items']['field'].serialize(colander.null) print print "Widget test:" form=deform.Form(sch) print urllib.unquote(form['items'].widget.prototype(form['items'])) Result: Schema test: true Widget test: <li title=""> <!-- sequence_item --> <span class="deformClosebutton" id="deformField3-close" title="Remove" onclick="javascript:deform.removeSequenceItem(this);"></span> <input type="checkbox" name="field" value="true" id="deformField3"/> <!-- /sequence_item --> </li> colander.serialize() work well Please pull my commit to fix it |
I've got the same problem here. Here was my test case @view_config(renderer='templates/form.pt', name='sequence_of_selects_with_default')
@demonstrate('Sequence of sequence Widgets with default')
def sequence_of_selects(self):
choices = (('habanero', 'Habanero'), ('jalapeno', 'Jalapeno'),
('chipotle', 'Chipotle'))
class Peppers(colander.SequenceSchema):
pepper = colander.SchemaNode(
colander.String(),
default='jalapeno',
validator=colander.OneOf([x[0] for x in choices]),
widget=deform.widget.SelectWidget(values=choices),
title='Pepper Chooser',
description='Select a Pepper')
class Schema(colander.Schema):
peppers = Peppers()
schema = Schema()
form = deform.Form(schema, buttons=('submit',))
return self.render_form(form) |
The following also allow to set the default value for the initial items
|
I fixed this differently due to changes on the master, but thank you for the analysis, it was spot-on! |
Code example:
class SequenceItem(colander.Schema):
name = colander.SchemaNode(colander.String())
enabled = colander.SchemaNode(colander.Bool(),
default='true',
missing=u'')
class Sequence(colander.SequenceSchema):
items = SequenceItem()
class Schema(colander.Schema):
name = colander.SchemaNode(colander.String())
items = Sequence()
schema = Schema()
form = deform.Form(schema, buttons=('submit',))
When I press "Add Items" in browser "Enabled" checkbox is unchecked.
I fix this problem