This project is archived and is in readonly mode.
Remote forms with multiple submit controls don't report which submit was used, under Unobtrusive JavaScript
Reported by Chowlett | November 18th, 2010 @ 11:51 AM
(Rails 3.0.0)
Consider a simple view:
<%= form_tag({:action => 'debug'}) do %>
<%= submit_tag "Foo" %>
<%= submit_tag "Bar" %>
<% end %>
When this is submitted (by normal POST), the parameters includes
"commit" => "Foo"
or "commit" =>
"Bar"
.
However, if the form is using unobtrusive javascript to make it an AJAX request:
<%= form_tag({:action => 'debug'}, {:remote => true}) do %>
<%= submit_tag "Foo" %>
<%= submit_tag "Bar" %>
<% end %>
... then the parameters do not carry the submit control which
was used. This is because the function callRemote
in
rails.js
uses serializeArray
on the form;
but serializeArray
doesn't take account of the control
used to submit the form.
I have patched my local app by making use of
originalEvent
, but I have no means of using Git (my
corporate firewall blocks the SSH port). How can I get my patch
considered?
Comments and changes to this ticket
-
Andrew White November 18th, 2010 @ 12:17 PM
- Importance changed from to Low
Is this in the prototype or jquery version of rails.js?
It appears to be fixed in the prototype version:
https://github.com/rails/prototype-ujs/commit/f60d60dddcf0dd1f1ae45...If you want to make a patch but you are behind a firewall then you can use a http clone url and submit a patch as described in the contributor guide.
-
Chowlett November 18th, 2010 @ 12:19 PM
jQuery version. Thanks for the HTTP link - I'll look into getting a patch up.
-
Chowlett November 18th, 2010 @ 12:55 PM
Patch file below. Apologies for the patch comment; I had to change my author details post-commit.
I'm not very experienced with JavaScript, so it's entirely possible this is a horrible way to fix the problem. I also don't understand the test-suite enough to update the tests, I'm afraid. Still, for what it's worth, here's the patch.
-
Neeraj Singh November 18th, 2010 @ 04:27 PM
- Assigned user set to Neeraj Singh
Take a look at this. https://github.com/rails/jquery-ujs/issues#issue/18
The tests are failing for this pull request on FF. Not sure why. I will take a look this weekend.
-
Chowlett November 18th, 2010 @ 04:54 PM
Neeraj - a quick check with FireBug confirms what I was trying to workaround with the
originalEvent
;e.target
is the form element, not the submit control. -
pederbl (at jobstar) November 25th, 2010 @ 05:40 PM
i just copied the prototype fix in jquery syntax and it works great for me. what is the best way to apply the fix.
why is the priority low for this? it seems like a major bug to me.
-
Neeraj Singh November 25th, 2010 @ 05:58 PM
- Importance changed from Low to Medium
Can someone add test for the patch?
-
Neeraj Singh December 8th, 2010 @ 03:57 AM
- State changed from new to resolved
Chris:
Can you submit your patch as a pull request on juqery-ujs. It's much easier to manage all tickets at one place (jquery-ujs issues).
Thanks
-
Chowlett December 15th, 2010 @ 02:39 PM
Sorry, I'm still very new to Lighthouse and git. Can you clarify / explain what you want me to do, exactly?
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>