On Tue, 18 Jul 2006, Alberto Valverde wrote:

> You can pass any instance as a value to the form and it's attributes
> will be fetched as values for the child widgets (the form's fields).
> Something like:
>
> class User(SQLObject):
>       name = StringCol(alternateId=True)
>       age = IntCol()
>
> class MyForm(TableForm):
>       fields = [
>               TextField('name'),
>               TextField('age'),
>               ]
>
> form = MyForm()
> form.display(User.byName('alberto'))

presumably I'd use the display method as follows:

     @expose(template=".templates.form")
     def editUser(self, tg_errors=None, *args, **params):
         if tg_errors:
             turbogears.flash("Error on form: " + str(tg_errors))
         id = params.get("id", None)
         if (id):
             try:
                 user = User.get(id)
                 user_form.display(user)
             except SQLObjectNotFound:
                 raise NotFound()
         return dict(form=user_form, action='saveUser', title='Edit User')

Sadly, that does not work, I continue to get an empty form client-side. 
Also, one wonders about the safety of multiple threads using same 
user_form instance simultaneously, but that's another topic I have yet to 
even dive into.

fwiw, my form template is very simple, copied from one of the form 
generator examples in the wiki:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";
     xmlns:py="http://purl.org/kid/ns#";
     py:extends="'master.kid'">

<head>
     <meta content="text/html; charset=UTF-8" http-equiv="content-type" 
py:replace="''"/>
     <title>${getattr(self,'title','Forms Tutorial')}</title>
</head>

<body>

     <p py:content="form(action=action)">Comment form</p>

</body>
</html>

Apologies for my appalling ignorance, but I'm having trouble with the lack 
of forms widget documentation. :) If I'm able to get this identity 
management app working, I'll be happy to wiki it on up for others to learn 
from.

- donald

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to