Am 16.05.2011 um 23:57 schrieb m8ram:

Hi,

I've recently started a small project using turbogears and I ran into
a problem that I believe from what I found so far can best be solved
by using a form validator.

Only I can't figure out how to add a validator to my form.  And so far
I've been unable to find a tutorial or other documentation that
explains this on a level I can grasp it.

The problem at hand is that I've created a multi select on a form (in
one of the templates) and I want to make sure that for this parameter
is returned as a list even when only one option is selected.

According to 
https://groups.google.com/group/turbogears/browse_thread/thread/9ad78837dcd9ac5f?fwc=1&hl=hy
I should use a validator for this.

I've read http://turbogears.org/2.0/docs/main/Validation.html but to
me that's a giant leap from the 20-minutes wiki tutorial and I can't
figure out what to add to the controller, what to add to the template,
what to import etc.

http://www.turbogears.org/2.0/docs/main/ToscaWidgets/Cookbook/PasswordValidation.html
also appears to rely on background knowledge I haven't picked up yet.

Can someone point me to some documentation to help me with this?

I'm not aware of "better" docs here, I don't read docs that much these days ;)

This applies to your issue:

  
http://turbogears.org/2.0/docs/main/Validation.html#validating-arguments-without-form-widgets

Your code should look roughly like this (only focussing on the differences to your current setup):

from tg import validate
from formencode import ForEach
from formencode.validators import Int

@expose(...)
@validate(dict(my_param=ForEach(Int(not_empty=True), convert_to_list=True))
def my_action(...):


HTH,

Diez

--
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en.

Reply via email to