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.

Patch that adds an exception

#2347

<%= link_to 'bla', '#', {:onclick => "document.merge_form.submit()", :confirm => "Really?"}%>

will result in


<a onclick="return confirm('Really?');" href="#">bla</a>

with my onclick just eaten without any notice. If this isn't done for a specific reason I would propose 2 possible solutions. Allow only one of the two being set and throw an exception Wrap the onclick JS in the confirm

I totally understand that I will have to write the patch myself and just wanted to check if this is not for some reason intended behaviour, if it is I could add a comment on this to the link_to method.

Reported by nasmorn · March 26th, 2009 @ 01:34 PM

State: invalid
Milestone: 3.x
Assigned to: Ryan Bigg Ryan Bigg
Importance: Low

Activity

  1. Jeff
    Jeff
    • Tag changed from action_view, javascript, link_to to action_view, javascript, link_to

    I can't speak to what the intention is here, but if you look at the documentation for the link_to_function method, you'll one example of what you're trying to do

    
      link_to_function(image_tag("delete"), "if (confirm('Really?')) do_delete()")
    

    http://api.rubyonrails.org/class...

    Maybe raising an exception or a warning would be a good idea, but I'm not sure that wrapping the onclick in the confirm is obvious.

    April 5th, 2009 @ 10:07 PM

  2. nasmorn
    nasmorn
    • Tag changed from action_view, javascript, link_to to action_view, javascript, link_to, patch
    • Title changed from :confirm overwrites :onclick to Patch that adds an exception

    I hope this is acceptable, it does pretty much what the other exception does

    April 6th, 2009 @ 02:41 PM

  3. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  4. Ryan Bigg
    Ryan Bigg
    • State changed from new to incomplete
    • Importance changed from to Low

    Please add tests to this patch.

    October 6th, 2010 @ 02:10 AM

  5. Ryan Bigg
    Ryan Bigg
    • Tag changed from action_view, javascript, link_to, patch to action_view, needs_tests

    October 6th, 2010 @ 02:11 AM

  6. Ben Mills
    Ben Mills
    • Assigned user set to Ryan Bigg

    In Rails master seems to do just what it should. Rails 3 utilizes the HTML5 attribute data-confirm to handle the confirmation.

    <%= link_to 'bla', '#', {:onclick => "document.merge_form.submit()", :confirm => "Really?"}%>
    

    Outputs:

    <a href="#" data-confirm="Really?" onclick="document.merge_form.submit()">bla</a>
    

    Since it seems unnecessary, my vote:

    -1

    October 6th, 2010 @ 02:58 AM

  7. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 9th, 2010 @ 10:14 PM

  8. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 19th, 2010 @ 08:23 AM

  9. Jeff Kreeftmeijer
  10. Piotr Sarnacki
    Piotr Sarnacki
    • State changed from incomplete to invalid

    I'm closing that. As Ben noticed, 3.x is no longer adding stuff to onclick attribute.

    December 17th, 2010 @ 10:36 AM

  11. bingbing