This project is archived and is in readonly mode.
Problem with prototype UJS and pictures as links
Reported by Jérémie Horhant (Titinux) | May 21st, 2010 @ 05:23 PM | in 3.0.5
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
Comments and changes to this ticket
-
Santiago Pastorino May 21st, 2010 @ 11:25 PM
Yeah, you should fork rails/prototype-ujs patch and do a pull request
-
Jérémie Horhant (Titinux) May 22nd, 2010 @ 11:53 PM
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 ?
-
José Valim May 22nd, 2010 @ 11:58 PM
Yup. It seems that Rails master code is almost up to date to rails/prototype-ujs one.
-
José Valim May 22nd, 2010 @ 11:58 PM
- Assigned user changed from José Valim to josh
-
Christiaan Van den Poel June 23rd, 2010 @ 11:56 AM
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
-
Christiaan Van den Poel June 23rd, 2010 @ 01:35 PM
- no changes were found...
-
Jeremy Kemper June 28th, 2010 @ 03:47 AM
- State changed from new to open
- Milestone cleared.
- Importance changed from to Low
-
Jeremy Kemper June 28th, 2010 @ 03:47 AM
- Importance changed from Low to High
-
Mislav February 5th, 2011 @ 08:35 PM
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)
-
Santiago Pastorino February 5th, 2011 @ 08:36 PM
- State changed from open to resolved
Thanks Mislav
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>