Re: multiple input fields validation

"Marcin StÄ™pnicki" <[email protected]> Wed, 31 Dec 2008 11:40:10 +0100
Newsgroups gmane.comp.python.formencode
Message-ID <[email protected]>
On Tue, Dec 30, 2008 at 11:04 PM, Ian Bicking <[email protected]> wrote:
> If you call variabledecode on the values, you'll get {'finish_date':
> ['date1', 'date2', ...]}.  You can do this in the schema with
> prevalidators=[formencode.variabledecode.NestedVariables()].
>
> Once you get the exception, you want to do something like:
>
> try:
>    ...
> except Invalid, e:
>    errors = e.unpack_errors(encode_variables=True)
>
> Then the error dict will loko like {'finish_date-1': None, 'finish_date-2':
> 'some error'} (assuming the first field is fine and the second is not).
>  This should work as input to htmlfill.

Yes, it works for error messages, thank you very much (I've also made
a mistake with enumeration - I should start input id from 0, not 1).
The only problem left was defaults, but I've used variable_encode and
it works like a charm.

In case anyone is interested:

http://pastebin.com/m7b5f7494

Oh, and by the way: FormEncode sphinx documentation has invalid links
from built-in search engine. For example:

http://formencode.org/search.html?q=NestedVariables&check_keywords=yes&area=default

Gives link to:

http://formencode.org/modules/variabledecode?highlight=nestedvariables
instead of proper:
http://formencode.org/module-formencode.variabledecode.html

Thank you all for your help!

------------------------------------------------------------------------------