Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

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

#6001

(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?

Reported by Chowlett · November 18th, 2010 @ 11:51 AM

State: resolved
Milestone: none
Assigned to: Neeraj Singh Neeraj Singh
Importance: Medium

Activity

  1. Andrew White
    Andrew White
    • 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.

    November 18th, 2010 @ 12:17 PM

  2. Chowlett
    Chowlett

    jQuery version. Thanks for the HTTP link - I'll look into getting a patch up.

    November 18th, 2010 @ 12:19 PM

  3. Chowlett
    Chowlett

    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.

    November 18th, 2010 @ 12:55 PM

  4. Neeraj Singh
    Neeraj Singh
    • 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.

    November 18th, 2010 @ 04:27 PM

  5. Chowlett
    Chowlett

    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.

    November 18th, 2010 @ 04:54 PM

  6. pederbl (at jobstar)
    pederbl (at jobstar)

    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.

    November 25th, 2010 @ 05:40 PM

  7. Neeraj Singh
    Neeraj Singh
    • Importance changed from Low to Medium

    Can someone add test for the patch?

    November 25th, 2010 @ 05:58 PM

  8. Neeraj Singh
    Neeraj Singh
    • 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

    December 8th, 2010 @ 03:57 AM

  9. Chowlett
    Chowlett

    Sorry, I'm still very new to Lighthouse and git. Can you clarify / explain what you want me to do, exactly?

    December 15th, 2010 @ 02:39 PM

  10. bingbing