甜蜜警报停止,除非我按下确认按钮

问题描述 投票:0回答:1

我有一个很大的验证 javascript 规则 - 在我应该允许提交表单之前列出.. 为了保持示例简单,我只显示前 4 个规则语法简化...

$("#SubmitForm").submit(function() {
     
// Some variables defined...

        
        if (Condition check 1)
{                                   
                Swal.fire({ 
                title: 'Attention!',
                text: "Warning Text1",
                icon: 'warning',
                confirmButtonColor: '#3085d6',
                confirmButtonText: 'Return'
                })
                return false; 
        }else if (Validation Rule 2){ 
           Swal.fire({       
              title: 'Attention',
              icon: 'error',
              html: 'Notify user for possible problem',
              showCloseButton: false,
              focusConfirm: false,
              confirmButtonColor: '#3085d6',
              confirmButtonText: 'Return'
            })
           return false;
        }else if (Validation Rule 3){ 
              Swal.fire({         
              title: 'Attention',
              icon: 'warning',
              html: 'Warning Msg with options menu',
              showCloseButton: false,
              reverseButtons: true,
              focusConfirm: true,
              confirmButtonColor: '#3085d6',
              cancelButtonText: 'Cancel',
              showCancelButton: true,
              confirmButtonText: 'Continue',
              
            }).then((result) => {
              if (result.isConfirmed) {
                **return true; //Should Continue to next validation check**
              }else{
                return false;  
              }
              
            });
            // Wait for user's choice...
        }else if (Validation Rule 4){ 
            return Swal.fire({ 

…………

如何继续下一个验证规则 4,在验证规则 3 的情况下,用户按继续。

(我正在向您展示简化的代码,以尽可能保持代码的简洁...)

javascript sweetalert2
1个回答
0
投票

可能最简单的方法是将整个

else if (Validation Rule 4){ ... }
块(当然没有 else if)移动到
if (result.isConfirmed) {}
条件中。

另一个选项是设置一些隐藏的输入值,这将触发 Validation Rule 4 然后再次调用提交表单调用

$("#SubmitForm").submit()
.

© www.soinside.com 2019 - 2024. All rights reserved.