Chris Newman
2006-Apr-19 13:28 UTC
[Rails] How to use multiple buttons on the same form with AJAX?
Hi, We are trying to use multiple submit buttons in the same form to tie to different actions on the server side. For example: <input name="commit" type="submit" value="edit"> <input name="commit" type="submit" value="cancel"> <input name="commit" type="submit" value="test configuration"> This works with non-AJAX type requests. However, now that we are trying to do the same with AJAX, it is not working. Whichever button we press, we get the value of the first button on the form being passed as a parameter to the server. It looks like to me the problem might be related to how Rails generates its buttons with the same name (commit) but different values. Is this legal in AJAX? Does AJAX use DOM? Is there a work-around for this? The parameters hash looks like... "commit" => "edit" even if we press the "cancel" or "test configuration" buttons. I have Googled about but haven''t found any answers. Can anyone point me in the right direction or recommend a good book on AJAX? Any help would be appreciated. Thanks, cn -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060419/170feb94/attachment.html
Edward Frederick
2006-Apr-19 14:00 UTC
[Rails] How to use multiple buttons on the same form with AJAX?
Chris, If I recall, this is a known issue with XHR and you just can''t. Ed On 4/19/06, Chris Newman <Chris.Newman@dalsemi.com> wrote:> > > Hi, > > We are trying to use multiple submit buttons in the same form to tie to > different actions on the server side. > > For example: > > > <input name="commit" type="submit" value="edit"> > > <input name="commit" type="submit" value="cancel"> > > <input name="commit" type="submit" value="test configuration"> > > > This works with non-AJAX type requests. However, now that we are trying to > do the same with AJAX, it is not working. Whichever button we press, we get > the value of the first button on the form being passed as a parameter to the > server. It looks like to me the problem might be related to how Rails > generates its buttons with the same name (commit) but different values. Is > this legal in AJAX? Does AJAX use DOM? Is there a work-around for this? > > The parameters hash looks like... > > "commit" => "edit" > > even if we press the "cancel" or "test configuration" buttons. > > I have Googled about but haven''t found any answers. Can anyone point me in > the right direction or recommend a good book on AJAX? > > Any help would be appreciated. Thanks, > > > cn > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Michael Greenly
2006-Apr-19 14:08 UTC
[Rails] Re: How to use multiple buttons on the same form with AJAX?
Edward Frederick wrote:> Chris, > > If I recall, this is a known issue with XHR and you just can''t. > > Eddef onclick_button_to( label, *options) button_to_function label, %Q{location.href=''#{url_for *options}''} end This is in my helper and what I use for my cancel buttons in my multi-button forms. You pass the same parameters as you would for link_to. In my view it looks like... <%= form_tag :action => "save" %> <%= onclick_button_to "cancel", :action => "index" %> <%= submit_tag ''save'' %> <%= end_form_tag %> This is non-ajax usage but you would just need to modify the javascript in the onclick_button_to method to get what you wanted... -- Posted via http://www.ruby-forum.com/.