uberllama
2010-Sep-24 20:46 UTC
Refiring click event from a custom confirm using Rails 3 UJS data-confirm binding
Hi folks. Been banging my head against the wall for a while on this one so figure I''d shoot it out there and see if anyone has insight. I''m overriding the document.on("click", "*[data-confirm]", function(event, element) method in rails.js, to call a custom dialog instead of a straight browser confirm box, like so. document.on("click", "*[data-confirm]", function(event, element) { if (!window._confirmed) { var message = element.readAttribute(''data-confirm''); Mylib.confirm(element, message); event.stop(); } }); What this does is load up a javascript dialog with a cancel and okay button. If the okay button is clicked, I set window._confirmed to true, call an onclick on the original element, then reset window._confirmed to false. This worked in Rails 2, since the javascript was all inline via an onclick. However I haven''t managed to re-trigger the click using the Rails 3 UJS method. Hoping someone has some insight to what''s probably a simple issue that I just can''t see right now. Cheers. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
uberllama
2010-Sep-24 22:28 UTC
Re: Refiring click event from a custom confirm using Rails 3 UJS data-confirm binding
Solved, using the fantastic event.simulate.js prototype extension. http://github.com/kangax/protolicious/blob/master/event.simulate.js On Sep 24, 2:46 pm, uberllama <uberll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi folks. Been banging my head against the wall for a while on this > one so figure I''d shoot it out there and see if anyone has insight. > I''m overriding the document.on("click", "*[data-confirm]", > function(event, element) method in rails.js, to call a custom dialog > instead of a straight browser confirm box, like so. > > document.on("click", "*[data-confirm]", function(event, element) { > if (!window._confirmed) { > var message = element.readAttribute(''data-confirm''); > Mylib.confirm(element, message); > event.stop(); > } > }); > > What this does is load up a javascript dialog with a cancel and okay > button. If the okay button is clicked, I set window._confirmed to > true, call an onclick on the original element, then reset > window._confirmed to false. This worked in Rails 2, since the > javascript was all inline via an onclick. However I haven''t managed to > re-trigger the click using the Rails 3 UJS method. > > Hoping someone has some insight to what''s probably a simple issue that > I just can''t see right now. Cheers.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.