I disagree, the behavior seems controllable to me and I use it often.
In IE, a submit done via the enter key on a text input doesn't send
any of the <input type='submit' values back.  On firefox, a submit
done with the enter key will send the first submit value. Just make
your default submit the first one and you can determine what to do
with your form. Here's a revised example:

    form = FORM('blah blah',
            INPUT(_type='text', _value='test',_name="test"),
            INPUT(_type='submit', _value='Reset',_name="reset"),
            INPUT(_type='submit', _value='Apply',_name="apply"),

            INPUT(_type='submit', _value='Reset
all',_name="resetall"))
    if request.vars.apply:
        pass #clicked or enter was hit on FF
    elif request.vars.reset:
        pass #clicked
    elif request.vars.resetall:
        pass #clicked
    else:
        pass #enter was hit on IE, do apply

Maybe I'm missing something?


On Feb 27, 8:06 pm, Iceberg <iceb...@21cn.com> wrote:
> I think Jonathan have given enough reason of why not.  There is
> another post to discuss the same 
> thing.http://groups.google.com/group/web2py/msg/79c1f847890a6b60
>
> In short, do resist the temptation of using multiple submit buttons,
> pal. :)
>
> On Feb28, 9:36am, "mr.freeze" <nat...@freezable.com> wrote:
>
> > Why not just do this?:
>
> > def index():
> >     form = FORM('blah blah',
> >             INPUT(_type='submit', _value='Apply',_name="apply"),
> >             INPUT(_type='submit', _value='Reset',_name="reset"),
> >             INPUT(_type='submit', _value='Reset
> > all',_name="resetall"))
> >     if request.vars.apply:
> >         pass #apply was clicked
> >     elif request.vars.reset:
> >         pass #reset was clicked
> >     elif request.vars.resetall:
> >         pass #resetall was clicked
>
> > On Feb 27, 6:30 pm, Jonathan Lundell <jlund...@pobox.com> wrote:
>
> > > On Feb 27, 2010, at 4:03 PM, Thadeus Burgess wrote:
>
> > > > If your running the latest version of web2py, look at
> > > > controllers/appadmin.py in ccache function. It defines a form with
> > > > three buttons, (one toc lear ram, one to clear disk, and one to clear
> > > > both). Click the different submit button executes the appropriate
> > > > function.
>
> > > A caveat, though: this approach is problematical if the form has a text 
> > > input field and the user submits the form by typing return in an input 
> > > field, rather than clicking a button.
>
> > > The problem as I understand it is that in that case you're not guaranteed 
> > > which button is returned. The culprit (no surprise) is IE. So if Tom's 
> > > form gets submitted by a return in a text field, and the browser is IE, 
> > > he presumably wants to see the Apply button, but might see one of the 
> > > reset buttons instead--not what the user intended.
>
> > > My approach is to use one submit button, and to make the other buttons 
> > > type=button, with an onclick script to reinvoke the same controller with 
> > > a button ID in vars. You'll typically check for that at the beginning of 
> > > the controller.
>
> > > I've been using it for a cancel button, as well as some 
> > > application-specific functions, and it seems to work well.
>
> > > > -Thadeus
>
> > > > On Sat, Feb 27, 2010 at 5:08 PM, Jonathan Lundell <jlund...@pobox.com> 
> > > > wrote:
> > > >> On Feb 27, 2010, at 3:00 PM, Tiago Almeida wrote:
>
> > > >> Don't know why functions reset, reset_all are not called but they 
> > > >> reference
> > > >> a "form" variable which is not in scope? Do you have any global "form"?
>
> > > >> The logic below can't work, for lots of reasons.
> > > >> One is the one Tiago mentions. Another is that input elements do not 
> > > >> have
> > > >> action attributes; forms do. There are ways to accomplish this kind of
> > > >> thing; most of them involve JavaScript.
> > > >> This might be helpful (though it's not the way I'd do
> > > >> it):http://www.javascript-coder.com/html-form/html-form-submit.phtml
>
> > > >> Regards,
> > > >> Tiago
> > > >> --
>
> > > >> On Sat, Feb 27, 2010 at 10:15 PM, Tomas Pelka <tompe...@gmail.com> 
> > > >> wrote:
>
> > > >>> Hi all,
>
> > > >>> have some troubles with web form which have more than one button. It 
> > > >>> is
> > > >>> obvious that one button (action connected with button) correspond with
> > > >>> one function.
>
> > > >>> According manual this should work:
> > > >>> controler
> > > >>> ---------
> > > >>> def index():
> > > >>>  form = FORM('blah blah',
> > > >>>        INPUT(_type='submit', _value='Apply'),
> > > >>>        INPUT(_type='submit', _value='Reset', _action=URL(r=request,
> > > >>> f='reset'),
> > > >>>        INPUT(_type='submit', _value='Reset all', 
> > > >>> _action=URL(r=request,
> > > >>> f='reset_all'))
> > > >>>  if form.accepts(request.vars, session):
> > > >>>        pass
> > > >>>  elif form.errors:
> > > >>>        response.flash = 'Error'
> > > >>>  else:
> > > >>>        pass
> > > >>>  return dict(form=form)
>
> > > >>> def reset():
> > > >>>    if form.accepts(request.vars, formname=None):
> > > >>>        response.flash = 'Reset'
> > > >>>    elif form.errors:
> > > >>>        response.flash = 'Error'
> > > >>>    else:
> > > >>>        pass
> > > >>>    return dict()
>
> > > >>> def reset_all():
> > > >>>    if form.accepts(request.vars, formname=None):
> > > >>>        response.flash = 'Resert all'
> > > >>>    elif form.errors:
> > > >>>        response.flash = 'Error'
> > > >>>    else:
> > > >>>        pass
> > > >>>    return dict()
>
> > > >>> But action functions (reset, reset_all) will not call. Am I doing
> > > >>> anything wrong?
>
> > > >>> Thanks for advice,
> > > >>> cheers
>
> > > >>> --
> > > >>> Tom
>
> > > >>> Key fingerprint = 06C0 23C6 9EB7 0761 9807  65F4 7F6F 7EAB 496B 28AA
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to