On Jul 17, 2006, at 4:59 AM, Javier Rojas wrote:

> Hi
>
> I have a multipleSelectField, and when I use a validator with it, the
> validation and conversion is made over every selected element (e.g,  
> with
> validators.Int); if I select no items from it, the validator  
> doesn't get
> called. I need the validator to check if the list (the selected  
> elements) is
> empty. What validator should I use?

You should be abe to do something like:

w = MultipleSelectField("mselect", validator=Int(not_empty=True))

This should make sure at least one option is selected. IIRC browsers  
don't even send a variable name for a multiple select if no options  
are chosen. You can provide a failsafe value fo this scenario by  
passing it to the validator as the 'if_empty' parameter:

w = MultipleSelectField("mselect", validator=Int(if_empty=2))

> other question:
> how can I use validators with compound widgets? I've defined  
> validators for
> all the elements within the compound widget, but they don't seem to  
> work.

Validators for compound widgets should subclass  
turbogears.validators.Schema. If you don't define one for the  
compound widget itself then a schema will be automatically generated  
including every validator present in the child widgets. If this is  
not working for you, can you please submit some code that presents  
this behavior? Maybe you've found a bug or maybe you're just doing  
something wrong... ;)

As Jorge pointed out, SelectShuttle is a good example of a  
CompoundFormField where you can look for insipiration

Alberto

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to