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?

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?

Kevin H.

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

lmwangi wrote:
> Hi all,

Hi,

>  I am trying to set up default values for widgets in TG. By calling
> AddAdminFields with a dictionary that has the defaults. so that the
> name widget now becomes
> name =
> widgets.TextField(validator=validators.NotEmpty,default='SomeAdmin')..
>
> Is there a way i can do this? I have tried using methods to modify the
> class vars but ....
> Here is a snip

Pass at the form display method your prepopulated dict:

form.display(value=default_values)

where:

default_values = dict(name="SomeAdmin")

name is the name of your fields, if you also have email you can do
this:

default_values = dict(name="SomeAdmin", email="[EMAIL PROTECTED]")

rember that form and default_values are passed by your controller
method.


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