2

I've a delete button generated by the link_to helper method. It produces the following markup.

<a href="/clips/150" class="btn btn-mini btn-danger" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a>

When, I click this button, it opens confirm dialog box as expected.

However, I want to override this confirm dialog box. I want to show a confirm dialog box using Bootbox.

So, I tried to unbind the click events from these buttons. I've tried all the following ways (in console). But none works.

$('a[data-confirm]').unbind('click')

or,

$('a[data-confirm]').off('click')

or,

$('a[data-confirm]').undelegate('click')

Even, I tried click.rails as event name as I see this is the declaration in jquery_ujs.js.

$(document).delegate(rails.linkClickSelector, 'click.rails', function(e) {

You may ask me to remove :confirm => true when calling helper method. But I don't want that. I want that as default feature. I will override runtime. How can I achieve that?

4

2 回答 2

1

尽管我询问了如何覆盖 rails ujs 默认确认方法,但我的实际意图是使用引导框确认对话框而不是默认浏览器的确认框。

我在这里得到了开箱即用的解决方案。我在这里链接这个,以便它帮助其他有类似要求的人:

https://gist.github.com/2823526

于 2012-11-14T12:32:59.533 回答
1

如何覆盖默认的确认操作?参见 UJS 的源代码:

// Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
confirm: function(message) {
  return confirm(message);
},
于 2012-11-14T11:43:59.463 回答