Skip to content

Commit cd206d3

Browse files
Arknistaabm
authored andcommitted
Core: Add deprecation warning to 'date' method (jquery-validation#2138)
Ref jquery-validation#1787
1 parent a0bc9c4 commit cd206d3

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/core.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,9 +1385,26 @@ $.extend( $.validator, {
13851385
},
13861386

13871387
// https://jqueryvalidation.org/date-method/
1388-
date: function( value, element ) {
1389-
return this.optional( element ) || !/Invalid|NaN/.test( new Date( value ).toString() );
1390-
},
1388+
date: ( function() {
1389+
var called = false;
1390+
1391+
return function( value, element ) {
1392+
if ( !called ) {
1393+
called = true;
1394+
if ( this.settings.debug && window.console ) {
1395+
console.warn(
1396+
"The `date` method is deprecated and will be removed in version '2.0.0'.\n" +
1397+
"Please don't use it, since it relies on the Date constructor, which\n" +
1398+
"behaves very differently across browsers and locales. Use `dateISO`\n" +
1399+
"instead or one of the locale specific methods in `localizations/`\n" +
1400+
"and `additional-methods.js`."
1401+
);
1402+
}
1403+
}
1404+
1405+
return this.optional( element ) || !/Invalid|NaN/.test( new Date( value ).toString() );
1406+
};
1407+
}() ),
13911408

13921409
// https://jqueryvalidation.org/dateISO-method/
13931410
dateISO: function( value, element ) {

0 commit comments

Comments
 (0)