如果存在多个$ .confirm,则jquery-confirm暂停脚本

时间:2018-01-17 11:45:58

标签: javascript jquery

我提交了一份提交验证表单。 我希望在表单提交时添加超过1个提醒:

var proceed = true;

$.confirm({
    title: 'Confirm 1',content: 'No products added. Are you sure to proceed?',
    buttons: {
                ok: {
                        text: "OK",
                        btnClass: 'btn-success',
                        action: function () {
                                }
                    },
                cancel: {
                        text: "Cancel",
                        action: function () {
                            proceed = false;
                            return false;   
                            }
                        }
            }
      });

... some others checks ....

if ( !proceed ) { return false;} //EXIT SCRIPT

// IF ALL CHECKS PASSED
$.confirm({
   title: 'Final confirm',content: 'All checks are ok. Are you sure to insert?',
    buttons: {
                ok: {
                        text: "OK",
                        btnClass: 'btn-success',
                        action: function () {
                                form.submit(); //SUBMIT THE FORM
                            }
                    },
                cancel: {
                        text: "Cancel",
                        action: function () {
                                // CLOSE DIALOG
                                }
                        }
           }
   });

但是在表单提交上我会打开所有2个$.confirm!我想暂停第二个,直到我在第一个点击OK。

我的jsfiddle https://jsfiddle.net/st1cqb39/2/

1 个答案:

答案 0 :(得分:0)

finalConfirm函数作为通用函数,并相应地在action回调(空检查)中调用它。

以下是演示: https://jsfiddle.net/st1cqb39/3/

希望这有帮助!