I am trying to add a validator rule which will work like:
When we apply this rule on an element then it should only be validated on the non-empty values of the elements which we passed through params. Means, it must validate itself if and only if one of the passed elements have non-empty value.
the rule what I am trying:
jQuery.validator.addMethod("reqAfter",function(a,b,c){
for(var i in c){
var $d=$(c[开发者_StackOverflow社区i]);
return !($d.length&&$d.val()!==""&&a=="");
}
},"Please provide some value!");
like:
rules: {
sField: { reqAfter: ['#startD', '#endD'] },
startD: { regex: /^(\d{4,4})-(\d{2,2})-(\d{2,2})$/, reqAfter: ['#sField'] },
endD: { regex: /^(\d{4,4})-(\d{2,2})-(\d{2,2})$/, reqAfter: ['#sField', '#startD'] }
}
for this form:
I sort it by myself.
Working validator method is:
jQuery.validator.addMethod("reqAfter", function (e, b, a) {
if (!a || a.length < 1) return !0;
else {
var b = !1,
c;
for (c in a) {
var d = $(a[c]);
if (d.length && d.val() !== "") {
b = e === "" ? !0 : !1;
break
}
}
return !b
}
}, "Please provide some value!");
Thanks to me...
精彩评论