SweetAlert2 确认对话框在 onclick 中无法正常工作

SweetAlert2 confirm dialog not working properly in onclick

如何修复 sweetalert2 确认对话框在 onclick 事件按钮中无法正常工作?

我有一个模态弹出窗口,用于在提交 sweetalert2 确认对话框之前进行 CRUD 操作。

这是我的模态表单代码:

<form id="EditForm" asp-action="Edit">
<div class="modal-body">
    
    /*input codes here*/
</div>
<div class="modal-footer justify-content-between">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    <button type="submit" class="btn btn-success btn-flat" onclick="return submitResult()"><i class="far fa-check-circle"></i> Save Changes</button>
</div>

这是js代码:

function submitResult() {
        Swal.fire({
            title: 'Are you sure?',
            text: "You won't be able to revert this!",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, delete it!'
        }).then((result) => {
            if (result.isConfirmed) {
                Swal.fire(
                    'Deleted!',
                    'Your file has been deleted.',
                    'success'
                )
                return true;
            }
            else {
                return false;
            }
        })
    }

Sample output

Apply edit, it still does not work

试试这个

<button type="submit" class="btn btn-success btn-flat" onclick="submitResult(event)"><i class="far fa-check-circle"></i> Save Changes</button>

....

function submitResult(e) {
    e.preventDefault();
    Swal.fire({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
    }).then((result) => {
        if (result.isConfirmed) {
            Swal.fire(
                'Deleted!',
                'Your file has been deleted.',
                'success'
            )
            document.getElementById("EditForm").submit();
        }
    })
}