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);

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.

Solved, using the fantastic event.simulate.js prototype extension.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs