[EMAIL PROTECTED] wrote:
> So, at the suggestion of several people on the list today, I figured
> out the basics of using form widgets. So now my little toy learning
> application (a wish list) is all widgety. Neat stuff. However, my
> design for this program relies on the same sort of new/not new status
> for the list items that the wiki20 tutorial uses to tell the "save"
> class how to handle the form data. I can't for the life of me figure
> out how to implement that sort of mechanism using the widgets. I tried
> a ton of different things, and none of them work. Any guidance would be
> appreciated.
>
As Kevin said, if what you need is passing values at display time to
your widgets that's what you can do.
Let's take the wiki20 Form:
<form action="save" method="post">
<input type="hidden" name="pagename" py:attrs="value=pagename"/>
<textarea name="data" py:content="data" rows="10" cols="60"/>
<input type="submit" name="submit" value="Save"/>
</form>
In Widgets language :D this becomes something like:
class MyFields(WidgetsList):
name = HiddenField()
data = TextArea()
wiki20_form = TableForm(name="page", fields=MyFields(),
action="save",
submit_text="Save")
Now if you problem is passing a value to the hidden field, that's what
you will do from your edit method (for example):
@turbogears.expose(html="wiki20.templates.edit")
def edit(self, pagename):
page = Page.byPagename(pagename)
form_values = dict(name=page.pagename, data=page.data)
return dict(form=wiki20_form, form_values=form_values)
in your edit.kid page you will need to do this then:
form.display(value=form_values)
One thing to keep in mind, if you're using a CompoundFormField (ATM a
FieldSet for example) it means you are using a nested field, the value
you get as input associated to such a field is not a plain value but a
dictionary containing its field, value pair.
For example:
class NestedFields(WidgetsList):
one = TextField()
two = TextField()
class MyFields(WidgetsList):
name = TextField()
nested = FieldSet(fields=NestedFields())
myform = TableForm(fields=MyFields(), action="save")
your save method needs to be something like this:
def save(self, name, nested):
The basic rule is that you just expect the parameter you've listed in
the WidgetsList class that you are passing as fields to the form
Widget, in this case fields=MyFields() so we use name and nested.
now when you submit such a form that's what you get as input:
name = "myname"
nested = {"one": "hey", "two": "hello"}
the same rule applies if you need to pass dynamically computed values
to your form for the first display, so in the previous example (wiki20)
you don't pass a flat dictionary but a nested dictionary like this one:
form_values = dict(name="michele",
nested=dict(one="yeah one",
two="really two"))
finally if you don't need to pass dynamically computed values of you
just want a field to always have a default value that should be used on
every first display of your form you can provide it at the widget
instantiation, for example:
name = TextField(default="Your name here!")
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
-~----------~----~----~----~------~----~------~--~---