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
input type="date" fails validation when using locale specific methods from localizations/ #2359
Comments
Yep, We are having the same issue. Given an When we activate the localized methods for Germany the date method validates against the format This has been open for quite some time now, so I do not expect it to get fixed any time soon. This forces us to not use the localized validation methods... I would like to help contribute a fix, but I don't think there is an easy approach to fixing this without causing breakage. Some ideas:
I wrote a really dirty script that fixes this issue -- incase someone needs this... // For more information see: https://github.com/jquery-validation/jquery-validation/issues/2359
$(function () {
$.validator.addMethod("formDate", function (value, element) {
var iso8601DateRegex = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
return (
$(element).is("input[type=date]") &&
iso8601DateRegex.test(value)
);
}, "This value does not match the ISO8601 form specification");
var rulesOriginal = $.prototype.rules;
$.prototype.rules = function () {
if (arguments.length === 0 && this.is("input[type=date]")) {
var originalRules = rulesOriginal.apply(this);
delete originalRules["date"];
originalRules["formDate"] = true;
return originalRules;
}
return rulesOriginal.apply(this, arguments);
}
}) |
@PatrickHollweck out of curiosity, does my one-line fix at #2360 not help? |
@tyomitch For various reasons, I cannot modify the jquery-validation script, Therefore I needed a solution that works without modifying the original source... Have not tested your change, but if it works it would be really nice if someone could merge it :) |
Test case contributed by @nenadvicentic
This issue/proposal has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automatically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up. |
I think this is wrong, and the problem still persists. |
* Core: Fix code style to pacify jscs * Core: Fix validation for input type="date" (#2359) Test case contributed by @nenadvicentic Co-authored-by: Kieran <kieran@supportpal.com>
https://jqueryvalidation.org/date-method/ says: This method is deprecated and will be removed in version
2.0.0
.Please don't use it, since it relies on the
Date
constructor, which behaves very differently across browsers and locales. UsedateISO
instead or one of the locale specific methods (in localizations/ and additional-methods.js).So we're using
localization/methods_pt.js
, and observing that it causes validation of date inputs to always fail, because they are unconditionally validated using the deprecated method, and not its suggested replacements.Environment
jquery@3.5.1
jquery-validation@1.19.2
jquery-validation-unobtrusive@3.2.11
Steps to reproduce
class="input-validation-error"
localization/methods_pt.js
is not loaded, then the validation succeeds -- even though our actual date format conforms tomethods_pt
This is because date input value is always in ISO format, regardless of the display format (reference)
Expected behaviour
normalizeAttributeRule
should matchdate
input type withdateISO
rule, instead ofdate
rule.The text was updated successfully, but these errors were encountered: