jConfirm alert - jQuery plugin

后端 未结 1 590
日久生厌
日久生厌 2021-01-27 08:04

Am jConfirm for user confirmation.

My first jConfirm doesnt stop for user action and just passes to next.

My Code:

    $(function () {

    $(\"#         


        
相关标签:
1条回答
  • 2021-01-27 08:45

    Not sure if this is all, but this part:

        if (JobHander.MaxInstances == 0) {
                jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
                    if (!ans)
                        return;
                });
        }
    

    probably doesn't do what you want. It is exiting the function(ans) { ... } function, while you probably want to exit the whole handler, i.e. $("#UpdateJobHandler").click(function () { ... }. If so, you would need to do similar to what you do below - i.e. put the whole thing in function(ans) { ... }, after the return. Probably best to separate into smaller functions.

    EDIT: Something along these lines:

        function afterContinue() {
           var json = $.toJSON(JobHander);
    
           $.ajax({
              // ... all other lines here ...
           });
        }
    
        if (JobHander.MaxInstances == 0) {
                jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
                    if (ans) {
                       afterContinue();
                    }
                });
        }
    

    You can do similar thing for all the success functions.

    Another example, you can rewrite the Instances check like this:

                function afterInstances() {
                            var JobHandlerNew = getJobHandler();
                            JobHandlerNew.FinalUpdate = "Yes";
    
                            // ... and everything under else branch ...
                }
    
                if (alertM == "Instances") {
                    jConfirm(message, 'Instances Confirmation?', function (answer) {
                        if (answer) {
                           afterInstances();
                        }
                    });
                }
    

    Important - rename the methods (afterContinue, afterInstances, ...) to have some name that means something useful to someone reading this in the future.

    0 讨论(0)
提交回复
热议问题