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.

Problem with prototype UJS and pictures as links

#4663

Hello,

I have a little problem with the click observer of the prototype UJS file. When you use an image as a link the confirmation popup does not show up.

link_to ..., {:confirm => 'Are you sure ?'), :method => :delete} do
  image_tag ...
end

which produce this html

<a href="..." data-confirm="Are you sure ?" data-method="delete" rel="nofollow"><img src="..." /></a>

The click observer (line 61 of railties/lib/rails/generators/rails/app/templates/public/javascripts/rails.js)

  $(document.body).observe("click", function(event) {
    var message = event.findElement().readAttribute('data-confirm');
    if (message && !confirm(message)) {
    event.stop();
    return false;
  }

In this case the event.findElement() does not return the link but the image and that why data-confirm can't be found.
I suggest to replace event.findElement() by event.findElement("a") and findElement will go up to find the a markup.

Sorry for my ignorance but how can I make a patch ? Fork rails/prototype-ujs, make the correction, commit and make a pull request ?

Thanks in advance.
Jérémie Horhant

Reported by Jérémie Horhant (Titinux) · May 21st, 2010 @ 05:23 PM

State: resolved
Milestone: 3.0.5
Assigned to: josh josh
Importance: High

Activity

  1. Santiago Pastorino
    Santiago Pastorino

    Yeah, you should fork rails/prototype-ujs patch and do a pull request

    May 21st, 2010 @ 11:25 PM

  2. Jérémie Horhant (Titinux)
    Jérémie Horhant (Titinux)

    The code on rails/prototype-ujs project is very different from the one in rails-3.0.0.beta3. Am I supposed to correct the code in rails/prototype-ujs ?

    May 22nd, 2010 @ 11:53 PM

  3. José Valim
    José Valim

    Yup. It seems that Rails master code is almost up to date to rails/prototype-ujs one.

    May 22nd, 2010 @ 11:58 PM

  4. José Valim
    José Valim
    • Assigned user changed from José Valim to josh

    May 22nd, 2010 @ 11:58 PM

  5. Christiaan Van den Poel
    Christiaan Van den Poel

    Sorry to bump in on this, but I wanted to help on this :)

    The problem is related to prototype 1.6 and event delegation.

    The eventTarget for the click event isn't the a-tag as you would expect but it's the img-tag. And the 'data-confirm' is only defined on the a-tag, so you would never get the confirm dialog.

    I've tried to patch this in the rails/prototype-ujs repo, but as this one is for prototype edge (1.7_rc2) which handles event delegation much better than the 1.6 (stable) version, this is not an issue here.

    So the problem only exists for the rails.js version included in the rails/rails repo (which targets prototype 1.6). For this one I've created the following patch.

    Currently, the only tags that can have a 'data-confirm' attribute are a-tags and input-tags. When the event.findElement() doesn't return one of these it uses event.findElement('a[data-confirm]') to find the parent a-tag with the attribute set. it searches only for a-tags as these are the only ones who can contain childelements as opposed to input-tags.

    Hope this helps

    June 23rd, 2010 @ 11:56 AM

  6. Christiaan Van den Poel
  7. Christiaan Van den Poel
  8. Jeremy Kemper
    Jeremy Kemper
    • State changed from new to open
    • Milestone cleared.
    • Importance changed from to Low

    June 28th, 2010 @ 03:47 AM

  9. Jeremy Kemper
    Jeremy Kemper
    • Importance changed from Low to High

    June 28th, 2010 @ 03:47 AM

  10. Jeremy Kemper
  11. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.

    Automatic cleanup of spam.

    October 15th, 2010 @ 07:15 AM

  12. Jeremy Kemper
  13. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 19th, 2010 @ 08:22 AM

  14. Santiago Pastorino
  15. Mislav
    Mislav

    Sorry this bug didn't get any attention from the prototype-ujs maintainers. Currently that's me, and I only check issues on its github project.

    This bug is obsolete, as my refactoring in rails.js worked around this bug a long time ago. If you still experience issues, please report it at the right place. Thanks

    (This can be closed)

    February 5th, 2011 @ 08:35 PM

  16. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to resolved

    Thanks Mislav

    February 5th, 2011 @ 08:36 PM

  17. Santiago Pastorino