Eric Woroshow wrote:
> Hi all,
> 
> Is it somehow possible to retrieve the set of form errors reported by
> the validate decorator in semantic order? By that I mean get a list of
> errors in the same order as the field definitions in the schema. I'm
> pretty sure the answer is "no" but I figured it couldn't hurt to ask.
> 
> What I would like to produce is a single error box with all the form
> errors to display above the form. Right now I'm just concatenating
> c.form_errors.itervalues() but of course that spits out errors in
> alphabetical order by field which is, I feel, confusing. Maybe there's
> a better way to approach this problem? Certainly I could produce an
> error template for each form but that doesn't strike me as very DRY.
> Alternatively I could pass the form error dictionary back as JSON (all
> the form submits are via Ajax) and make the client figure it out but
> that seems like a lot of work that I would prefer to avoid. Thoughts?

Well, one option would be to look at the order of the fields in the 
form.  This is probably a better ordering than the order of the 
validators in the schema.  You can order the validators, as all 
validators get an incremented integer when they are created 
(validator.declarative_count); if you sort on that you should get them 
in the order they were defined.  But Schema doesn't use that, and they 
all get put into a dict.  We'd need to use some kind of MultiDict thing 
to keep them ordered, and that would have to happen at several points 
(at least inside Schema, and variable_decode).

[input.name for input in lxml.html.fromstring(form).forms[0].inputs] 
will do it in lxml.  Something based on HTMLParser for 
formencode.htmlfill would be welcome as well.

   Ian

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
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