繁体   English   中英

Active Admin - 如何在更新表单时添加“确认”弹出窗口

[英]Active Admin - How to add a 'confirm' pop up when a form is being updated

是否可以在活动管理表单中向更新操作添加确认类型警报?

我的意思是,当用户单击表单上的Update时,我希望弹出一个警报(很像单击Delete时弹出的警报),要求他们确认他们是否确定......

我在表格中有以下内容:

f.actions 

似乎这应该是一件简单的事情,但我无法弄清楚它想要什么?

现在我的active_admin.js文件中有以下内容:

$("#order_submit_action").submit(function(e) {
    alert("Are you sure?");
    e.preventDefault();
});

但它不起作用?! (也没有 JS 错误)

提前致谢

app / assets / active_admin.js.coffee中

$ ->
  $('form').submit (event)->
    if confirm 'Are you sure?'
      true
    else
      event.preventDefault()

用您自己的匹配器替换$('form') ,它应该很好用!

由于某种原因, .submit()没有任何作用,所以我用以下方法解决了:

$(function() { 
    $("form input[type=submit] ").on("click", function(){
    var con = confirm("Are you sure you want to update this?");
        if (con == true) {

        }
        else
            return false;           
}); 
});

Ruby 上轨

Rails 上的 Ruby 允许您使用数据属性添加确认对话框。

<%= f.submit 'Save', data: { confirm: 'Are you sure?' } %>

活动管理员

在 ActiveAdmin / Formtastic 中,您可以通过button_html来利用 Rails 的这种行为。 不需要额外的 JavaScript。

f.actions do
  f.action :submit, button_html: { 'data-confirm': 'Are you sure?' }
  # Preserve the usual cancel button and its styling.
  f.action :cancel, as: :link, label: 'Cancel', wrapper_html: { class: 'cancel' }
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM