Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery alertify confirm after confirm does not work

I am using Alertify Jquery plugin for my dialogs. The problem is that a confirm after a confirm does not seem to work:

<img onclick="go()" src="test.jpg">
<script type="text/javascript">
// confirm dialog
function go(){

  alertify.confirm("Reset password?", function (e) {
    if (e) {
        // user clicked "ok"
        secondconfirm();
    } else {
        // user clicked "cancel"
    }
  });
}

function secondconfirm(){

  alertify.confirm("Password is changed<br>Mail it to the user?", function (e) {
    if (e) {
        //Done
        alertify.success("Password reset and mailed to user.");
    } else {
        // user clicked "cancel"
        alertify.success("Password reset.");
    }
  });
}
</script>

I want to use it this way because based on clicking yes or no a second question has to be asked. If I use it like this, the second confirm dialog appears very shortly and then pops out of screen. Even more annoying, the DIV that covers the rest of the screen stays in place so I can't even use the site naymore without refreshing the whole page. I guess it has something to do with the first dialog being faded out, also hiding the second one.

How to solve this?

like image 767
Mbrouwer88 Avatar asked Oct 04 '22 23:10

Mbrouwer88


1 Answers

Try to delay the execution of the secondconfirm method's body by using the setTimeout method:

function secondconfirm() {
    setTimeout(function () {
        alertify.confirm("Password is changed<br>Mail it to the user?", function (e) {
            if (e) {
                //Done
                alertify.success("Password reset and mailed to user.");
            } else {
                // user clicked "cancel"
                alertify.success("Password reset.");
            }
        });
    }, 1000); // I went as low as 300 ms, but higher value is safer :)
    return true;
}
like image 71
Alex Filipovici Avatar answered Oct 13 '22 09:10

Alex Filipovici