I think I've found the solution - the key is to make sure you specify a 
position when you add the child exception to the parent one. This may only 
be a deform_bootstrap issue - I haven't done enough digging to be sure.

def main_schema_validator(form, value):
    subnode = child_named('sub_node', form)
    try:
       sub_schema_validator(subnode, value['sub_node'])
    except colander.Invalid, e:
       exc = colander.Invalid(form)
       # NB: You NEED the 0 argument here, or the error won't display
       # May be a deform_bootstrap problem
       exc.add(e, 0)
       raise exc

Hope that helps someone.

On Tuesday, July 10, 2012 6:27:28 PM UTC+2, sirdavidoff wrote:
>
> Basically I'm struggling to add a multi-field validation error generated 
> by on a child schema to the parent schema. Here goes...
>
> I have a schema which includes a subschema:
>
> class SubSchema(Colander.Schema):
>    url = colander.SchemaNode(...)
>    description = colander.SchemaNode(...)
>
> class MainSchema(Colander.Schema):
>    sub_node = SubSchema()
>    ...
>
> I also have a validation function that checks that at least one of 'url' 
> and 'description' is non-null:
>
> def sub_schema_validator(form, value):
>    if not value['url'] and not value['description']:
>       exc = colander.Invalid(form, 'Must enter either a website or a 
> description')
>       exc['url'] = ''
>       exc['description'] = 'Please enter either a website or a description'
>       raise exc
>
> This function works fine if I just use the sub-schema (no main schema). 
> For the main schema, I've tried to write a function that calls the 
> sub-schema validation function:
>
> def main_schema_validator(form, value):
>     subnode = child_named('sub_node', form)
>     sub_schema_validator(subnode, value['sub_node'])
>
> The error gets raised, but the 'url' and 'description' fields don't get 
> highlighted like they should be. I'm not sure how I'm supposed to add the 
> exception generated by the sub-node to one for the main node.
>
> Any ideas?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/pylons-discuss/-/LeDh0216K8gJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to