2
votes

I'm using bootbox to confirm a user action.

I have a button that submits a form, and when that button is clicked I need the user's confirmation to submit or cancel:

$(document).ready(function() {
    $(btn_continue).click(function(){

        bootbox.confirm('Are you sure?', function(result){
            if (result) {
                form.submit();
            }
            else {
                return false;
            }
        });

    });
});

the problem is popup appears then disappear without waiting for the user click! Please why this happens?

1
Please post a working fiddle in order to reproduce your issue...Hackerman
Hi @Hackerman, I add that btn_continue is a submit button. I hope this is enough.MeBex

1 Answers

0
votes

Try it removing your else and using type button in your #btn_continue:

$("#btn_continue").click(function(e) {
    bootbox.confirm('Are you sure?', function(result){
      if (result) {
        $("#form").submit();
      }
    });
});

JsFiddle: http://jsfiddle.net/v0h7fer7/

Explanation: The bootbox is closing because you are posting your form before it. The click event handler ends before the result of bootbox.confirm, and allow your button type="submit" to post your form. bootbox.confirm is an assynchonus call.