最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootbox callback not working properly - Stack Overflow

programmeradmin4浏览0评论

I'm trying to use this:

 $('#delete').live('click',function(){
                var result;
                bootbox.confirm("Are you sure?", function(response){
                        result=response;
                });
                alert(result);
                return result;
            });

But when the button is clicked:

Alert is shown first and only after that bootbox shows confirm dialog.

I want to return the response , but if i do it from within call back it doesn't work because it returns response from callback but not $('#devicedelete').live('click',function(){});

Btw i'm trying to submit a form basing on response. So if i return 'true' form will be submitted, else if it returns 'false', form wont be submitted.

Please check this:

I have one big table with checkboxes for each row, users select checkboxes and click on any of the buttons 'delete' , 'copy' etc and form should be submitted.

Thanks

I'm trying to use this:

 $('#delete').live('click',function(){
                var result;
                bootbox.confirm("Are you sure?", function(response){
                        result=response;
                });
                alert(result);
                return result;
            });

But when the button is clicked:

Alert is shown first and only after that bootbox shows confirm dialog.

I want to return the response , but if i do it from within call back it doesn't work because it returns response from callback but not $('#devicedelete').live('click',function(){});

Btw i'm trying to submit a form basing on response. So if i return 'true' form will be submitted, else if it returns 'false', form wont be submitted.

Please check this: http://pastebin./9H3mxE9Y

I have one big table with checkboxes for each row, users select checkboxes and click on any of the buttons 'delete' , 'copy' etc and form should be submitted.

Thanks

Share Improve this question edited May 26, 2013 at 14:47 Pruthvi Raj Nadimpalli asked May 26, 2013 at 13:32 Pruthvi Raj NadimpalliPruthvi Raj Nadimpalli 1,3731 gold badge16 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

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/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/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
});
发布评论

评论列表(0)

  1. 暂无评论