[英]How can I use Active Admin's form block to update a table that tracks when an attribute in a resource is updated?
[英]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;
});
});
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.