验证不会忽略字段

Validation doesn't ignore field

我正在使用插件 JQuery-Validate。我实际上创建了一个具有以下输入的表单:

<div class="form-group bmd-form-group">
    <label for="operator-password" class="bmd-label-floating"> <?= lang('password') ?> *</label>
    <input type="password" class="form-control" id="operator-password" name="password" >
</div>

<div class="form-group bmd-form-group">
    <label for="operator-confirm-password" class="bmd-label-floating"> <?= lang('confirm_pwd') ?> *</label>
    <input type="password" class="form-control" id="operator-confirm-password" name="confirm_password">
</div>

本质上,如果发生某种情况,我会动态应用 class .ignore,例如:

$('#operator-password, #operator-confirm-password').addClass('ignore');

当我提交表单时,我会得到以下两个输入:

Field is required!

这很奇怪,因为我将 validate 配置为使用 .ignore class:

跳过输入
$('#operator-form').validate({
    rules: {
        ignore: ".ignore",
        password: {
            required: true,
            minlength: 8
        },
        confirm_password: {
            equalTo: '#password'
        }
    },

您需要在 rules 之外提及 ignore,如下所示

$('#operator-form').validate({
    ignore: ".ignore",
    rules: {
        password: {
            required: true,
            minlength: 8
        },
        confirm_password: {
            equalTo: '#password'
        }
    }
})

https://jsfiddle.net/rL60wes2/