WOW!!!

I don't know how it works, but it does.  I used the second form in the 
example,

${form(options=formParams['options'])}

...and it worked on the first try.  I'm going to have to think about 
this one to get it straight in my head how it works.  Thanks so much for 
all the help, this opens up a lot of new good stuff for me with my 
development.  Will also help when I get to filling one dropdown based on 
the value in another.  But for me, that's a whole separate battle. 

Thanks again, I certainly appreciate the help.

    -Jim

Ian Wilson wrote:
> Here is how you would do it using tg widgets.
> # Setup our form, yada yada.
> form = TableForm(fields=[SingleSelectField(name='plantId'),...],...)
>
> # Get the plants for the given user and display them in a single select field.
> @expose(...)
> @validate(...)
> @error_handler(...)
> def getPlantsForUser(self, userId):
>     user = User.get(userId)
>     plants = Plant.select(Plant.q.userID == user.id)
>     # The name of this variable isn't specific to tg I just use it to hold 
> data.
>     # But notice that the params tree down to the specific field in
> the form(plantId).
>     formParams = dict(options=dict(plantId=[(plant.id, plant.name) for
> plant in plants]))
>     return dict(form=form, formParams=formParams)
>
> Now in the display:
>
> ${form(**formParams)}
>
> Or if you want more detail:
>
> ${form(options=formParams['options'])}
>
> Disgusting detail follows:
>
> The widget param system is kind of hard to explain.  All widgets take
> certain params but when their are child and parent widgets the parents
> can take params that go to their children and pass them down.  So in
> the case of a form its like a parent with a bunch of children(fields
> like SingleSelectField).  So when you pass options to the form it
> looks inside the options dictionary for the names of its children and
> then passes those values down to those children.  And this system
> works for more than 2 layers.  So if you have something like a field
> set in a form you have to pass a param to the form which then goes to
> the field set and then to the fields in the field set like this:
> form = TableForm(fields=[FieldSet(name='FullName',
> fields=[TextField(name='FirstName'), TextField(name='LastName')])])
> You would pass in the value param like this:
> form(value=dict(FullName=dict(FirstName= 'Ian', LastName='Wilson')))
>
> Value and options are not that special they are just params in the
> normal system that works for all widgets that let's you dispatch
> params from a parent widget to its children.
>
> Its actually pretty slick.  Hope this helps.
>
> -Ian
>
> On 2/28/07, Jim Steil <[EMAIL PROTECTED]> wrote:
>   
>>  You are correct in assuming that I am including this SingleSelectField as
>> part of a TableForm.  Therefore, I need to use the latter example.  Given
>> the latter example, would I specify the params parameter in my kid page
>> template something like this?
>>
>>  ${widget(value=formValues, action=submitAction, params=params)}
>>
>>  Can someone help out with the child_args parm?  I looked through the widget
>> browser and through the source but was unable to come up with anything.
>>
>>      -Jim
>>
>>
>>  wavydavy wrote:
>>  On Feb 27, 8:34 pm, Jim Steil <[EMAIL PROTECTED]> wrote:
>> [snip]
>>
>>
>>  But, then I wouldn't know how to specify it on my field def. Here is
>> what I do for the non-filtered dropdown:
>>
>> plant = SingleSelectField(label='Plant:',
>> options=qlfOptions.getUserPlantOptions)
>>
>> I don't know where I'd supply the parameter. Would I do it somehow in
>> the controller?
>>
>>  Yes, in the controller:
>>
>> user_plant_widget = SingleSelectField('plants', options=[]) # put
>> default/dummy options in
>>
>> @expose('project.templates.user_plant'
>> def plant(self, user):
>>  options = qlfOptions.getUserPlantOptions(user)
>>  return dict(widget=user_plant_widget,
>> params=dict(options=options))
>>
>> And somewhere in user_plant.kid:
>>
>> ...
>> ${widget.display(**params)}
>> ...
>>
>> That will pass the options in when the page is rendered for the given
>> user.
>>
>> If your SingleSelectField is part of a form or other compound widget,
>> you'll need to pass the options differently. I can't remember the
>> syntax exactly for TG widgets, but for ToscaWidgets I think it would
>> be (untested, from memory)
>>
>> @expose('project.templates.user_plant'
>> def plant(self, user):
>>  options = qlfOptions.getUserPlantOptions(user)
>>  child_args = dict(plants=dict(options=options)) # child
>> named
>> 'plants' gets the keyword argument 'options'
>>  return dict(widget=user_plant_widget,
>> params=dict(child_args=child_args))
>>
>> The pattern for TG widgets is similar, but it's not "child_args", its
>> something else, and I think the structure might be different.
>> Sorry, can't remember any docs on it, I had to grok the source to
>> figure it out back then. I've been using toscawidgets since they were
>> released, much better IMO.
>>
>> HTH
>>
>> --
>> wavy davy
>>
>>
>>
>>  return dict(widget=
>>
>>
>>
>>
>>
>>
>>  >
>>
>>     
>
> >
>   

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