Catch rails确认框动作

时间:2014-12-12 10:53:11

标签: ruby-on-rails ujs

我有以下rails按钮:

<%=
  link_to "Remove Product", product_path(product),
    remote: true,
    method: :delete,
    data: { confirm: 'Are you sure you want to delete this product?' }
%>

我正在使用rails-ujs来显示confirm()对话框;有一个简单的方法用javascript捕获确认答案吗?

2 个答案:

答案 0 :(得分:2)

有一个confirm:complete回调;这个没有记录,据我所知,我是looking at the source找到的。

这在confirm()电话后立即执行:

$(document).on 'confirm:complete', (e, answer) ->
  alert "Your answer was: #{answer}"
  return true # You can still cancel by returning false here

答案 1 :(得分:-1)

你可以处理onclick事件并使用它:

if (confirm("Say hello?")) {
  alert("hello!");
  ....
} else {
  .....
  alert("another")
}