durusmail: quixote-users: How to add/remove widgets dynamically?
How to add/remove widgets dynamically?
2003-07-22
How to add/remove widgets dynamically?
A.M. Kuchling
2003-07-22
On Tue, 22 Jul 2003 13:33:05 +0100 (WEST), Joao Pedro Pedroso
 wrote:
> I am trying to manage this in the 'process()' member of class derived
> from 'Form', adding the new widgets there.  I did not have success,
> even though I tried many different possibilities...

Try doing it in the __init__ of the class, with logic something like this
(typed from memory, so there are likely to be errors):

   def __init__ (self, request):
       Form.form.__init__(self, request)
       self.add_widget("submit_button", "add", ...)
       if self.get_widget_value("add"):  # XXX not sure this is the right
check
           self.add_widget("string", "fieldname", ...)

Note that Quixote comes with a List widget for having a list of identical
subwidgets;
the user can add new ones so they can enter an arbitrary number of items,
and
I think blank fields get forgotten, so you may not need to do this dynamic
widget creation yourself.

--amk


reply