On Tue, 8 May 2007 at 21:05, AZMel wrote:
> I changed my controller to pass this:
>
> return dict(modelname = self.modelname,
> record = record,
> form = model_form, defaultID = reachID.id,
> tg_paginate_limit=tg_paginate_limit,
> tg_paginate_no=tg_paginate_no,rootDir=self.rootDir)
>
> and I modified what you wrote to this:
>
> <span py:strip="True"
> py:content="form.fields[1].display(value=defaultID)">SingleSelectField</
> span>
>
> Now I get a select field showing on top of my existing form form with
> the value I want to be defaulted to. I can refresh, go back and
> select a new record to edit without getting the threadsafe error. This
> does get me a lot closer.
>
> Would I have to build the form manually, by displaying all the fields
> like I did with form.fields[1].display to get this to work, or is
> there a way to change the form object being passed to the template
> beforehand?
Sorry I misled you earlier about setting default. I didn't realize
that you couldn't set that attribute at display time, though I should
have realized it.
The syntax I showed is correct for other attributes, like value, though.
That is, you can pass values to subwidgets by name. So if 'Reach' is
the name of your fields[1] widget, you'd do:
return dict(modelname = self.modelname,
record = record,
form = model_form,
value = dict(Reach = reachID.id),
tg_paginate_limit=tg_paginate_limit,
tg_paginate_no=tg_paginate_no,rootDir=self.rootDir)
and then in your template:
${form.display(value)}
That is, you render the whole form in one go, and you pass all the
field values in one dictionary. In fact, this is the whole design of
the widget system, so that when the form is posted, the values you get
in the keyword dictionary in your method that handles the post is in
exactly the format of the dictionary that you could pass to the display
method to set the values in the form if you redisplayed it (and this is
exactly what the error handling system does).
So, to set the 'current value' of all of the widgets when you display
the form, construct a dictionary keyed by the widget name with the
values being the values you want displayed, and pass that into the
form's display method as the 'value' parameter for the form.
--David
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---