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?
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.