Alertify dialog disappeared before confirming

旧时模样 提交于 2019-12-06 11:53:40

The source of your problem is that you are trying to show the same dialog again while its being closed. The default AlertifyJS dialogs are all singletons (one instance at all times).

You have 2 solutions for this:

  1. Delay showing the second confirm until the first confirm is actually closed.

    alertify.confirm("confirm ? ", 
        function onOk() {
            //delay showing the confirm again 
            //till the first confirm is actually closed.
            setTimeout(function () {
                alertify.confirm("confirm another time ?");
            }, 100);
        },
        function onCancel() {
            //no delay, this will fail to show!
            alertify.confirm("this will not be shown!");
        }
    );
    
  2. Create your own transient (multi-instance) confirm, simply inherit from the existing one.

    // transient (multi-instance)
    alertify.dialog('myConfirm', function factory(){ return {};},true,'confirm');
    alertify.myConfirm("confirm ? ", function(){
        alertify.myConfirm("confirm another time ?");
    });
    

    Note: be careful with this, as each call to a transient dialog will create a new instance, you may save references to launched instances and re-use them!

See demo here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!