I think what I'm looking for is a way to pass a Form or CompoundWidget values between the time the widget is created and the time the widget is rendered.
If I were to try to use the default keyword argument with data from a database (for example), wouldn't that be breaking the "statelessness" of widgets?
I think I just need to see a good example...there are several good example of widgetized forms for adding data, but I have yet to see one for _editing_ that data. If you know of one, please point me to it!
Kevin H.
On 5/25/06, Michele Cella <[EMAIL PROTECTED]> wrote:
Kevin Horn wrote:
> The part of widgets documentation that I'd like to see fleshed out are more
> examples of the FormWidgets and other CompundWidgets.
>
You're right... :-)
> For example, is there a way to set the values of all the widgets contained
> in a CompundWidget at once? Maybe by passing a list? This would make forms
> for editing info in the database much simpler.
>
You need to pass a dict to the CompoundWidget, just like you do with a
Form (that's a CompoundWidget), for example:
>>> from turbogears import widgets
>>> class HelloWidget(widgets.Widget):
... template = "<div>Hello $value</div>"
...
>>> class ManyHello(widgets.CompoundWidget):
... member_widgets = ["hello_widgets"]
... hello_widgets = []
... template = """
... <div xmlns:py=" http://purl.org/kid/ns#">
... <div py:for="" in hello_widgets"
... py:content="hello(value_for(hello),
**params_for(hello))"
... />
... </div>
... """
...
>>> many = ManyHello(hello_widgets=[HelloWidget(name="1"), HelloWidget(name="2") ], default={'1':'jorge', '2':'alberto'})
>>> print many.render() <DIV>
<DIV>
<DIV>Hello jorge</DIV></DIV><DIV><DIV>Hello
alberto</DIV></DIV>
</DIV>
>>> print many.render(value={'1':'michele', '2':'kevin'})
<DIV>
<DIV>
<DIV>Hello michele</DIV></DIV><DIV><DIV>Hello
kevin</DIV></DIV>
</DIV>
the concept is exactly the same for a Form widget.
Ciao
Michele
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

