Bootbox callback not working properly

I am 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 pressed:

A warning is displayed first, and only after that the boot box shows a confirmation dialog.

I want to return the answer, but if I do it from the inside, it does not work, because it returns the answer from the callback, but not $ ('# devicedelete'). live ('click', function () {});

Btw I am trying to submit a form based on the answer. Therefore, if I return the `` form '' will be submitted, otherwise, if it returns 'false', the form will not be submitted.

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

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

thanks

+7
source share
1 answer

The dialog box is asynchronous, you can immediately prevent the default action, and then call sending 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 a more detailed conversation with the OP, he also wanted to pass the value of the button in the query line, my solution for this is: 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 }); 
+4
source

All Articles