Bootbox callback not working properly

心已入冬 提交于 2019-12-05 04:23:23

The dialog is async, you can prevent the default action right away, and then call the submit if the user accepts. Here is an example: http://jsfiddle.net/ty5Wc/3/

$('#delete').on('click', function (e) {
    e.preventDefault();
    bootbox.confirm("Are you sure?", function (response) {        
        if(response) {
            $('#form').submit();
        }
    });
});
$('#form').submit(function () {
    //do your validation or whatever you need to do before submit
});

Edit: After talking more with OP, he also wanted to pass button value in the query string, my solution for that is here: http://jsfiddle.net/ty5Wc/5/

$('#delete').on('click', function (e, confirmed) {
    if (!confirmed) {
        e.preventDefault();
        bootbox.confirm("Are you sure?", function (response) {
            if (response) {
                $('#delete').trigger('click', true);
            }
        });
    }
});
$('#form').submit(function (e) {
    //do your validation or whatever you need to do before submit
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!