New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lessThan reports error if compared to empty field #2463
Labels
Milestone
Comments
I'm not sure if that's a bug, and it could also be considered a breaking change if changed.. |
I agree it could be a breaking change... |
One question about my custom methods is if I should create a class (like does j.validator.addMethod(
"lessThanIfOtherNotEmpty",
function (val1, element, param) {
var target = j(param);
// if (
// this.settings.onfocusout &&
// target.not(".validate-lessThanIfOtherNotEmpty-blur").length
// ) {
// target
// .addClass("validate-lessThanIfOtherNotEmpty-blur")
// .on("blur.validate-lessThanIfOtherNotEmpty", function () {
// j(element).valid();
// });
// }
var val2 = target.val(),
normalizer;
if ((rules = target.rules())) {
if (typeof rules.normalizer === "function") {
normalizer = rules.normalizer;
} else if (typeof this.settings.normalizer === "function") {
normalizer = this.settings.normalizer;
}
// If normalizer is defined, then call it to retreive the changed value instead
// of using the real one.
// Note that `this` in the normalizer is `element`.
if (normalizer) {
val2 = normalizer.call(element, val2);
// Delete the normalizer from rules to avoid treating it as a pre-defined method.
delete rules.normalizer;
}
}
if (val1 == "" || val2 == "") {
return true;
}
return val1 < val2;
},
"Please enter a lesser value."
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your environment
jquery-validate
: v1.19.3Current behavior
When using rule
lessThan
comparing to an empty field, error is triggered.Expected behavior
Error should only be triggered if both fields are populated; user could/should add
required
to the other field if necessary.Live demo
The text was updated successfully, but these errors were encountered: