Re: Chained validators and error messages
Andrea Riciputi <[email protected]> Thu, 5 Mar 2009 14:03:17 +0100
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
Since you wrote that this is something like a special case, whilst i'm finding myself using it over and over again, I'm wondering if there is a better/more standard way to put error message raised by a chained validator near a specific form field. Or, if the chained validator is the standard way to solve my problem. Basically, what I'm trying to do is to check if a field fulfill a certain constraint where the constraint varies with the value of another field. I thought that checking each field per se (according their own validation rules) and then checking them in combination (using a chained validator) was a good approach, but I'm a beginner so I might be wrong. Is there any more standar way to get this done? TIA, Andrea On 5 Mar, 2009, at 04:48, Ian Bicking wrote: > On Wed, Mar 4, 2009 at 3:57 AM, Andrea Riciputi <[email protected] > > wrote: >> I'm trying to make htmlfill to put the error message raised by a >> chained validator near a specific form field. >> >> To get this I've written a custom validator where the messages dict >> is >> defined like this: >> >> messages = {'my_error_label': u"Error message goes here" } >> >> then, if the conditions are not met I raise the Invalid exception >> like >> this: >> >> raise Invalid(self.message('my_error_label', state), >> values, state, >> error_dict={ >> 'my_error_label': Invalid(self.message('field_name', state), values, >> state) >> }) >> >> Despite the fact this gives me the expected result, I'm not sure I'm >> raising that exception in the correct way. I mean, I got the >> impression that the Invalid instance could be called in easier way, >> but I really can't see how. Any suggestion? > > Yeah, that's right -- it's a little awkward, but usually this > particular kind of exception is only raised in Schema, so people don't > see the awkwardness as much ;) > > > > -- > Ian Bicking | http://blog.ianbicking.org ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H