BootstrapDialog.Confirm 未等待提交

BootstrapDialog.Confirm Not Waiting Before Submission

我正在使用 Bootstrap 对话框在用户删除消息之前向他们显示样式精美的确认框。因此,我有类似

<form onsubmit='return confirmDelMsg()'>
...
</form>

javascript函数:

function confirmDelMsg() {
    BootstrapDialog.confirm('Are you sure you want to delete this message?', function(result) {
         return result;
     });
}

问题是这个确认弹出窗口出现了一毫秒,但没有等我点击是或否。然后消息还是被删除了。

那么我该如何解决这个问题?

这是我正在使用的库:顺便问一下,这个 BootstrapDialog 是叫库还是框架?

https://nakupanda.github.io/bootstrap3-dialog/

你知道其他图书馆吗?我也知道 bootbox.js 但它有同样的错误...

编辑:

function confirmDeleteMsg() {
    return BootstrapDialog.confirm("Are you sure you want to delete this message?", function(result) {
       if (result) {
           var deleteMsgForm =  document.getElementById('deleteMsgForm');
           if (typeof(deleteMsgForm) != 'undefined' && deleteMsgForm != null) {
              alert("HERE"); // this here is executing!!!
           }
           deleteMsgForm.submit(); // this is not executing?! why?
        }
    });
}

可能是因为confirmDelContact在确认之前就返回了。尝试:

<form onsubmit='return false;'>
...
</form>

然后在此处使用 Javascript 或 jQuery 提交:

function confirmDelMsg() {
    BootstrapDialog.confirm('Are you sure you want to delete this message?', function(result) {
         if (result)
             document.getElementById("deleteMsgForm").submit();
     });
}

注意这点:

请注意,submit() 函数提交时没有任何 name 属性。所以要小心,因为很多人都是这样做的:

<form id="deleteMsgForm" action="" method="post" onsubmit="return false;">
    <button type="submit" name="deleted" onclick="confirmDelMsg();">Delete Message</button>
    <input type="hidden" name="msgId" value="x" />
</form>

<?php
if (isset($_POST["deleted"])) {
   // this will NOT work with javascript submit() function!!!
   // because the submit() now doesn't have a name attr
}
// use instead the following:
if (isset($_POST["msgId"])) {
   deleteMsg($_POST["msgId"]);
}
?>