Hey Jamie,

you named your buttons:

 fooButton = SubmitButton(attrs={'value':'foo'})
 barButton = SubmitButton(attrs={'value':'bar'})

so the respective kw fields should be kw['fooButton'] and kw['barButton']
If these don't exist as well it might have the following reason

I am working more with Sprox than with TW, and sprox does _not_ give
SubmitButtons a name (<input type="submit" name="xyz" ... />)
You can check that out easily, navigate to the page where you form is
located, and view the html source in your browser, and have a look at the
submit buttons.
If they lack a name="xyz" field, then they will not be posted! there are
multiple ways to work around this, the easiest i can think of for now is to
give them a name manually:

barButton = SubmitButton(attrs={'value':'bar', 'name'='submit'})
(untested)

Give that a try, if this doesnt work, I'll throw together a small sample app
and try myself.

Goodluck :)



On Wed, Aug 26, 2009 at 7:16 PM, Jamie Bullock <
[email protected]> wrote:

>
>
> Hi Tom,
>
> Thanks for replying.
>
> The problem is that kw['submit'] results in a KeyError exception.
> Inspecting the kw dict shows there isn't element in the dict
> corresponding to the submit button itself.
>
> Any ideas?
>
> Jamie
>
> On 26 Aug 2009, at 13:41, Crusty wrote:
>
> > Hey Jamie,
> >
> > you answered your own question, or what is the problem with that?
> > It's done almost exactly the way you wrote it, except for some ugly
> > pecularities of how TW sets the value attribute, which is a bit
> > twisted.
> >
> > Could you be more specific what goes wrong on your code?
> >
> > Tom
> >
> > On Tue, Aug 25, 2009 at 4:40 PM, Jamie Bullock <
> [email protected]
> > > wrote:
> >
> >
> > Hi,
> >
> > I'm sure this is really simple, but I'm stumped right now.
> >
> > Basically, I want a form with multiple buttons to be processed by a
> > single handler, but run sections of handler code conditionally
> > depending on which button was pressed.
> >
> > class MyForm(TableForm):
> >    class fields(WidgetsList):
> >        fooButton = SubmitButton(attrs={'value':'foo'})
> >        barButton = SubmitButton(attrs={'value':'bar'})
> > new_my_form = MyForm("new_my_form")
> >
> > Then:
> >
> > def post(self, *arg, **kw):
> >
> >    if kw['submit'] == 'foo':
> >          do_something()
> >    if kw['submit'] == 'bar':
> >          do_something_else()
> >
> > Is this possible?
> >
> > Jamie
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > >
>
>
> >
>

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