Confirmation alert on clicking an action
ashishnitinpatil opened this issue · 1 comments
Sometimes one would like to have a confirmation prompt when performing a certain critical action or ones which may not be easily reversible. Not sure if this is a must have feature but I implemented this by adding a custom templates/admin/change_list.html
with following content -
{% extends "admin/change_list.html" %}
{% block extrahead %}
{{ block.super }}
<script>
(function() {
document.addEventListener("DOMContentLoaded", function(event) {
let inline_actions = document.querySelectorAll(".inline_actions input");
for (var i=0; i < inline_actions.length; i++) {
inline_actions[i].addEventListener("click", function(e) {
if(!confirm("Do you really want to " + e.target.value + "?")) {
e.preventDefault();
}
});
}
});
})();
</script>
{% endblock %}
It basically prompts user to confirm the action before it is submitted to the backend. If user has clicked it accidentally, he can safely say no & the e.preventDefault();
would execute & stop the inline action from submitting.
thanks for pointing this out. This is a good idea, though I don't think it is an essential feature. Not everyone needs it as this module already has support for intermediate (confirmation) pages. However, I think it would be great to have a paragraph about this. Would you mind submitting a PR, which adds this to the readme?
Many thanks!