简体   繁体   English

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

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

Is it possible to add a confirmation type alert to the update action in an active admin form?是否可以在活动管理表单中向更新操作添加确认类型警报?

What i mean is, when the user clicks Update on the form i want an alert to pop up (much like the alert that pops up when Delete is clicked) that asks them to confirm whether they are sure...我的意思是,当用户单击表单上的Update时,我希望弹出一个警报(很像单击Delete时弹出的警报),要求他们确认他们是否确定......

I have the following in the form:我在表格中有以下内容:

f.actions 

Seems like this should be a simple thing to do but i can't figure out what it wants?似乎这应该是一件简单的事情,但我无法弄清楚它想要什么?

I now have the following in my active_admin.js file:现在我的active_admin.js文件中有以下内容:

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

But it doesn't work?!但它不起作用?! (no JS errors either) (也没有 JS 错误)

Thanks in advance提前致谢

In app/assets/active_admin.js.coffee app / assets / active_admin.js.coffee中

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

Replace $('form') by your own matchers, and it should work nicely ! 用您自己的匹配器替换$('form') ,它应该很好用!

For some reason, .submit() was not having any effect so i solved with the following: 由于某种原因, .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 on Rails Ruby 上轨

Ruby on Rails allows you to add a confirmation dialog by using a data attribute. Rails 上的 Ruby 允许您使用数据属性添加确认对话框。

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

ActiveAdmin活动管理员

In ActiveAdmin / Formtastic, you can leverage this Rails behavior with button_html .在 ActiveAdmin / Formtastic 中,您可以通过button_html来利用 Rails 的这种行为。 No extra JavaScript needed.不需要额外的 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