http://trac.turbogears.org/turbogears/ticket/475

Comments and discussion please.  I think that this is a good addition
to the base widgets.  If not then I'll add it as a recipe for a custom
widget on the wiki.

(Copied from the ticket)

Sometimes you don't know what a SelectField's options are going to be
before you .insert() it and changing the options on the fly isn't
threadsafe.

Attached is a patch with a new widget called DynamicSelectField?. It's
essentially the same as a normal SelectField? except it pulls out it's
options from widget_value on .insert().

Examples:

<div>
    ${testwidget.insert(value=(3, [(1,"Apple"),(2,"Banana"),(3,"Pear")]))}
</div>
<div>
    ${testwidget.insert(value=(2, [(1,"Audi"),(2,"VW"),(3,"Ford")]))}
</div>

The first argument in the value tuple is the value of the option you
want to be selected and the second is a list of tuples containing the
options and their respective values and text.

With this method the data can still be passed when the widget is
nested in a Form Widget (or subclass thereof).


Lee

Reply via email to