# Refiring click event from a custom confirm using Rails 3 UJS data-confirm binding

**URL:** <https://www.ruby-forum.com/t/refiring-click-event-from-a-custom-confirm-using-rails-3-ujs-data-confirm-binding/195546>\
**Category:** Rails\
**Created:** [September 24, 2010, 10:48pm UTC](https://www.ruby-forum.com/t/refiring-click-event-from-a-custom-confirm-using-rails-3-ujs-data-confirm-binding/195546 "2010-09-24T22:48:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![uberllama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/a587f6/32.png) [@uberllama](https://www.ruby-forum.com/u/uberllama)\
**Post date:** [September 24, 2010, 10:48pm UTC](https://www.ruby-forum.com/t/refiring-click-event-from-a-custom-confirm-using-rails-3-ujs-data-confirm-binding/195546/1 "2010-09-24T22:48:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![uberllama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/a587f6/32.png) [@uberllama](https://www.ruby-forum.com/u/uberllama)\
**Post date:** [September 25, 2010, 12:29am UTC](https://www.ruby-forum.com/t/refiring-click-event-from-a-custom-confirm-using-rails-3-ujs-data-confirm-binding/195546/2 "2010-09-25T00:29:42Z")

</div>

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

> <https://github.com/kangax/protolicious/blob/master/event.simulate.js>
