Hi there,

I have run into similar issues in the past.  I have come up with two
solutions:

1) The standard way to provide preselected values to any widget at
request time is to pass in a values dictions in the template, such as:

${form.display(dict(select_field: [1, 2, 3]))}

I'm not sure of the exact syntax, but it is along those lines.  With
that, you could pass in a dict of values calculated in the controller
and passed to the template.

2) The other way is to set values in cherrypy.request in teh
controller method and then retrieve them in the myCallable default.
For example:

def myCallable():
  return cherrypy.request.bar.pets

class Foo(Controller):
  def method(self, id):
    bar = model.get(id)
    cherrypy.request.bar = bar


You can actually use both these idioms in many situations, but
SelectLists are a common use of them.

Anyway, I hope this helps.  My code examples may not be perfectly
accurate (going from memory), but I think you'll get the idea.

Good luck,
Krys

On Feb 11, 4:42 pm, "miya" <[EMAIL PROTECTED]> wrote:
> Hi, I have a little problem here. I need to preselect some options in
> a multiple select.
> I've been browsing the group and found out that all I have to do is to
> pass the default argument (default = [...]).
>
> The problem is that I have defined this select in a WidgetsList so
> that I don't actually know which values to select at that moment.
> I figured that I could pass a Callable that return me the list of the
> values I need.
> The problem is that the Callable has to know the id of the user I
> need.
>
> For example, suppose a User has some pets (say 'dog', 'cat',
> 'giraffe', 'alligator', 'anaconda', etc...), and in the form I need to
> pre-select tha animals/pets that some dude has. The question is how do
> I pass the user's id to myCallable?
>
> How do I do this?
>
> def formExample(widgets.WidgetsList):
> ...
> ...
>         pets = widgets.MultipleSelectField(
>                                         label = '',
>                                         name = 'pets',
>                                         options = getAllPets,
>                                         size = 5,
>                                         default = myCallable??
>                     )
>
> ...
> ...
>
> How do I pass the user's id to myCallable ?
>
> thanks in advanced!!!
>
> --
> miya


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

Reply via email to