收口后台表单确认事件
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// 后台通用表单确认事件代理,集中替代简单的 Blade 内联 onsubmit confirm。
|
||||
|
||||
let adminFormConfirmationsBound = false;
|
||||
|
||||
/**
|
||||
* 绑定后台通用提交确认。
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
export function bindAdminFormConfirmations() {
|
||||
if (adminFormConfirmationsBound || typeof document === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
adminFormConfirmationsBound = true;
|
||||
|
||||
document.addEventListener("submit", (event) => {
|
||||
if (!(event.target instanceof HTMLFormElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除、撤销、取消等不可逆操作统一由 Blade 提供确认文案。
|
||||
const confirmMessage = event.target.getAttribute("data-admin-confirm");
|
||||
if (confirmMessage && !window.confirm(confirmMessage)) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user