On Feb 6, 2007, at 2:39 PM, Daniel Haus wrote:

>
> To make it short, here's what I'm doing (using ToscaWidgets, trunk):
>
>     class ArticleForm(ListForm):
>         class ArticleWidgets(WidgetsList):
>             # (other fields cut out for readability)
>             categories = CheckBoxList(label_text="Kategorien",
>                                 options=lambda:[(cat.id, cat.title)
>                                                 for cat in
> Category.select()])
>
>         class ArticleSchema(Schema):
>             filter_extra_fields = True
>             allow_extra_fields = True
>
>             categories = ForEach(Wrapper(from_python=lambda c:c.id))
>
>         validator = ArticleSchema()
>         fields = ArticleWidgets()
>
> But obviously the Wrapper inside the ForEach gets lost somewhere.
> Running
> "tg-admin shell" I got:
>
>>> af=ArticleForm()
>>> cbl=af.fields[1]
>>> cbl.validator
>  << <ForEach object 117 validatorArgs=(<class
> 'toscawidgets.widgets.forms.core.DefaultValidator'>,)
> validators=[<class
> 'toscawidgets.widgets.forms.core.DefaultValidator'>]>
>
> When I pass the validator (ForEach(...)) as kwarg to the
> CheckBoxList's
> constructor it all works fine.
>
> Is there a better way to do this? Or will ToscaWidgets need it's own
> ForEach?

TW doesn't (currently) merge recursively schemas' and compound  
widget's validators. You'd have to place the ForEach insde the  
CheckBox widget for it to work:

class ArticleForm):
        validator = Schema(filter_extra_fields = True, allow_extra_fields =  
True)
        class fields(WidgetsList):
                ....
                categories = CheckBoxList(validator=ForEach(...))

Alberto

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to turbogears@googlegroups.com
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