Bug: Multiple Submit Buttons w/ form_remote_tag

what's the status on this bug? Is it something that's ever going to be fixed? I try to stay away from Ajax forms with multiple buttons because of this.

Mike

Mike Garey wrote:

what's the status on this bug? Is it something that's ever going to be fixed? I try to stay away from Ajax forms with multiple buttons because of this.

Mike

> > The following code placed in application_helper.rb or loaded via /lib > works around this problem while allowing normal submit_tag() useage. > This is not well tested, but seems to do the trick for me. > > class ActionView::Base > alias_method :rails_submit_tag, :submit_tag > def submit_tag(value = "Save changes", options = {}) > options[:id] = (options[:id] || options[:name] || :commit) > options.update(:onclick => "$('#{options[:id]}').value = > '#{value}'") > rails_submit_tag(value, options) > end > end > > So this rails code: > <%= submit_tag 'Transfer', :name => :submit %> > <%= submit_tag 'Check IN' %> > produces this HTML: > <input id="submit" name="submit" onclick="$('submit').value = > 'Transfer'" value="Transfer" type="submit"> > <input id="commit" name="commit" onclick="$('commit').value = 'Check > IN'" value="Check IN" type="submit"> > > > > derek.haynes wrote: > > I've run across a problem when attempting to submit a form with the > > form_remote_tag when the form contains multiple submit buttons. > > > > My form contains 2 submit buttons, a "Preview" button and a "Post > > Message" button: > > <%= submit_tag 'Preview' %> > > <%= submit_tag 'Post Message' %> > > > > When the form is submitted, the value of @params['commit'] is the > > value of the first submit tag ('Preview' in this case) no matter what > > button is used to submit the form. > > > > This is not present when changing the form to a standard non-ajax form. > > > > Any one else run across this problem or have a suggested fix? > > > > > > -- > > Derek Haynes > > HighGroove Studios - http://www.highgroove.com > > Atlanta, GA > > Keeping it Simple. > > 404.593.4879 > > -- > Posted via http://www.ruby-forum.com/. > > > >

With normal forms, if you give the submit button a different name attribute, the submitted parameters will contain an entry for it.

<%= submit_tag 'Preview', :name=>'preview' %>

params['preview'] is then defined on submission, and you can use that to figure out which button was pressed. No idea if this works for AJAX forms, but it seems like it should.

_Kevin