On Tuesday 26 May 2009 16:04:09 Diego Woitasen wrote:
> On Tue, May 26, 2009 6:50 am, Diez B. Roggisch wrote:
> > On Tuesday 26 May 2009 03:28:14 Diego Woitasen wrote:
> >> Hi,
> >>  I want to write a reusable form using TableForm as base class. I tried
> >> with this:
> >>
> >> class RuleForm(TableForm):
> >>   def __init__(self, id=None, parent=None, children=[], host_filter=[],
> >> **kw):
> >>     super(RuleForm, self).__init__(id,parent,children, **kw)
> >>     self.fields = [
> >>         TextField(id = 'description', label = 'Description'),
> >>     ]
> >>
> >> and this:
> >>
> >> class RuleForm(TableForm):
> >>   def __init__(self, id=None, parent=None, children=[], host_filter=[],
> >> **kw):
> >>     children = [
> >>         TextField(id = 'description', label = 'Description'),
> >>     ]
> >>     super(RuleForm, self).__init__(id,parent,children, **kw)
> >>
> >> without sucess.
> >
> > What does "without success" mean? You are aware, that in the latter
> > example
> > you simply override whatever children are passed?
> >
> > Besides, the simple problem of yours seems to be solvable using
> >
> >
> > common_widgets = [...] # list of widgets
> >
> > some_form = Form(children = common_widgets + some_other_widgets]
> >
> > Diez
>
> Means, it doesn't work. If I use fields outside the constructor works, for
> example:
>
> class RuleForm(TableForm):
>   fields = [
>     TextField(id = 'description', label = 'Description'),
>   ]
>
>   def __init__(self, id=None, parent=None, children=[], host_filter=[],
> **kw):
>     super(RuleForm, self).__init__(id,parent,children, **kw)
>
> That works, but I need fields inside the constructor because I want to use
> SelectionList or CheckboxList which contents could change in each use of
> RuleForm (quering data from database).

This is not intended to work. ToscaWidgets are instantiated once, and re-used.

To make selectfields display varying values, use a callable as 
options-parameter. 

def get_options():
      return some_options


class MyForm(TableForm):
       class fields(WidgetList):
               select_field = SingleSelectField(options=get_options)


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