this.optional() in jQuery validation method doesn't seem to work
Posted
by HiveHicks
on Stack Overflow
See other posts from Stack Overflow
or by HiveHicks
Published on 2010-06-08T08:56:00Z
Indexed on
2010/06/08
9:02 UTC
Read the original article
Hit count: 292
Hello, I've got a little problem here. I've got the following rule for one of my fields:
StartDate: {
required: isDelayed,
dateRU: true
}
isDelayed() returns false, so I guess StartDate field should be optional. However if I check it inside my dateRU method:
$.validator.addMethod(
"dateRU",
function(value, element) {
return this.optional(element) || isValidDate($.trim(value));
},
"Date is incorrect"
);
this.optional(element) always returns false for StartDate. I can't figure out what's wrong. Any ideas?
UPD. Does optional() returns true only if element is not required AND IS EMPTY? 'Cause that may be my problem.
© Stack Overflow or respective owner