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...
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:
$("#order_submit_action").submit(function(e) {
alert("Are you sure?");
e.preventDefault();
});
But it doesn't work?! (no JS errors either)
Thanks in advance
In 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 !
For some reason, .submit()
was not having any effect so i solved with the following:
$(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 allows you to add a confirmation dialog by using a data attribute.
<%= f.submit 'Save', data: { confirm: 'Are you sure?' } %>
In ActiveAdmin / Formtastic, you can leverage this Rails behavior with button_html
. No extra JavaScript needed.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.