Thanks, Michele!

That makes things much more clear.  One more question...should it be form.display()? or form.render()?  Both have been used in our discussion.  Which is correct?  Or do they both work?  Which is the preferred method?

Thanks,

Kevin H.

On 3/7/06, Michele Cella <[EMAIL PROTECTED]> wrote:

Kevin Horn wrote:
> Would this also work to populate the values in a form for editing some data
> in the database?  The form handling example in Trac only really covers
> _adding_ to the database, not editing.  It seems that this method would work
> for editing, but I'm a little thrown by the use of the term "default"
> values.  Does this just mean the values of the input elements?
>

Hi Kevin,

yes, this works also for editing (FastData uses it ;-)).

Let's make some things clear, when you are instantiating a widget you
can define it's default value using the default parameter (same goes
for options on selections widgets for example), but later you can just
override almost everything (but not the widget name since that's a
controller role), take a look at this:

>>> from turbogears.widgets import *
>>> test = TextField(name="age", default="13")
>>> test.render()
'<INPUT ID="form_age" TYPE="text" NAME="age" VALUE="13"
CLASS="textfield">'
>>> test.render(value="45")
'<INPUT ID="form_age" TYPE="text" NAME="age" VALUE="45"
CLASS="textfield">'
>>>

Now let's take a look at a form:

>>> class FormFields(WidgetsDeclaration):
...     name = TextField(default="kevin")
...     email = TextField(default="[EMAIL PROTECTED]")
...     spam = CheckBox(default=True)
...
>>> form = TableForm(fields=FormFields())
>>> form.render()

[...]
<TR>
<TD><LABEL CLASS="fieldlabel" FOR=""><TD><INPUT NAME="name" TYPE="text" CLASS="textfield" VALUE="kevin"
ID="form_name"></TD>
</TR>
<TR>
<TD><LABEL CLASS="fieldlabel" FOR=""><TD><INPUT NAME="email" TYPE="text" CLASS="textfield"
VALUE="[EMAIL PROTECTED]" ID="form_email"></TD>
</TR>
<TR>
<TD><LABEL CLASS="fieldlabel" FOR=""
<TD><INPUT ID="form_spam" TYPE="checkbox" CHECKED CLASS="checkbox"
NAME="spam"></TD>
</TR>
<TR>
[...]

>>> values = dict(name="michele", email=" [EMAIL PROTECTED]", spam=False)
>>> form.render(value=values)

[...]
<TR>
<TD><LABEL CLASS="fieldlabel" FOR=""
<TD><INPUT NAME="name" TYPE="text" CLASS="textfield" VALUE="michele"
ID="form_name"></TD>
</TR>
<TR>
<TD><LABEL CLASS="fieldlabel" FOR=""
<TD><INPUT NAME="email" TYPE="text" CLASS="textfield"
VALUE="[EMAIL PROTECTED]" ID="form_email"></TD>
</TR>
<TR>
<TD><LABEL CLASS="fieldlabel" FOR=""><TD><INPUT ID="form_spam" TYPE="checkbox" CLASS="checkbox"
NAME="spam"></TD>
</TR>
<TR>
[...]

> If so, where/when  would one call the form.display method?  Just before
> returning from the controller?  Somewhere in the template?  What's the
> _best_ way to do this?

You pass the form to the template scope along with the values you want
to edit, keep in mind that you can also pass a SQLObject to edit it if
you setted up the right fields (that's how FastData works).



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