删除依赖字段上的验证突出显示

时间:2014-03-31 17:13:16

标签: jquery jquery-validate

我需要验证两个字段。如果填写了任何字段,则验证应该是正确的(如果两个字段都为空,则验证失败)

我添加了以下验证器:

   //The adapter
        jQuery.validator.unobtrusive.adapters.add(
            'eparncr', [], function(options) {
                options.rules['eparncr'] = {};
                options.messages['eparncr'] = 'Error message';
            }
        );

        //The validation method
        jQuery.validator.addMethod("eparncr", function (value, element, params) {

            if ($('#val').val() == '' && $('#val2').val() == '') {
                return false;
            }

            return true;
        });

和HTML代码:

<input id="val" type="text" name="val" data-val="true" data-val-eparncr="" />   
<input id="val2" type="text" name="val2" data-val="true" data-val-eparncr=""  />

但是在验证之后我填写其中一个仍然突出显示为错误字段的字段。

示例:

enter image description here

左场填充但右侧有红色。 为什么会这样?

0 个答案:

没有答案