On Feb 8, 8:01 pm, Remi Jolin - SysGroup <[email protected]>
wrote:
> le 08.02.2009 18:21 Michel Albert a écrit:> Hi all,
>
> [...]
> > Am I doing something wrong?
>
> yes...
>
> option can be a callable so your "dynamic" form could be defined like that :
> def get_options():
>     return [
>                     (x, `x`) for x in range(10)
>                   ]
>
> dynamic_form = widgets.TableForm(
>             fields = [
>                widgets.CheckBoxList(
>                   name="tags",
>                   label=_('Tags'),
>                   options=get_options),
>                widgets.TextField(name='number', label=_('Number'),
> default=1, validator=validators.Number()),
>                widgets.TextField(name='title', label=_('Title'),
> validator=validators.String()),
>             ],
>             name='newForm',
>             submit_text=_('Save')
>             )
>
> and then
>
>     @expose( template="testfoo.templates.new" )
>     def new(self, tg_errors=None):
>         return dict( form=dynamic_form, action="save" )
>
>     @validate(dynamic_form)
>     @error_handler( new )
>     @expose()
>     def save(self, **kwargs):
>         return dict( locals=`locals()` )
>
> If your options come from a database and can change between 2 calls you
> can also pass the options at render time
>
>     @expose( template="testfoo.templates.new" )
>     def new(self, tg_errors=None):
>         return dict( form=self.dynamic_form, action="save" ,
> options=dict(tags=get_options())
>
> and pass these options to your template
> ${form.display(action=action, options=options)}

Many thanks for the quick reply. This looks a lot cleaner, is more
maintainable and works like a charm. :)
--~--~---------~--~----~------------~-------~--~----~
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