更新时间:2022-12-13 13:48:25
问题是您已将required
规则构建到自定义方法中.
The problem is that you've built the required
rule into your custom method.
$.validator.addMethod("refDataAcInput", function(value, element) {
return ($(element).val() == "" || $(element).data("hasValidSelectedValue") != null);
}, "The item must be a valid selected item.");
删除$(element).val() == ""
并替换为this.optional(element)
...
Remove $(element).val() == ""
and replace with this.optional(element)
...
$.validator.addMethod("refDataAcInput", function(value, element) {
return (this.optional(element) || $(element).data("hasValidSelectedValue") != null);
}, "The item must be a valid selected item.");
然后,如果您还希望该字段为required
,只需声明required
规则以及自定义的refDataAcInput
规则即可.
Then if you also want the field to be required
, just declare the required
rule along with your custom refDataAcInput
rule.
该插件的默认懒惰"验证现在应该可以按预期工作.
The plugin's default "Lazy" validation should now be working as expected.