问题
I am using jQuery UI version 1.12.1 and jQuery Validation v1.15.0
I created a datepicker as follow:
if ($.fn.datepicker) $(':input.date').datepicker({
changeMonth: true,
changeYear: true
});
By default, the date format will be mm/dd/yyyy, for example 01/26/2017, represent 26th January 2017.
I am trying to change the date format to be dd/mm/yyyy, so I change the datepicker as follow:
if ($.fn.datepicker) $(':input.date').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy'
});
Well, now the date format display correct as I wish, it become 26/01/2017, represent 26th January 2017.
However, it throw a red error message Please enter a valid date.. After my debugging, I found that the error message is actually come from the jquery.validate.js at line 357:
messages: {
// some other code
date: "Please enter a valid date.",
// some other code
},
Any idea how/why it throw this error message?
Is it my jQuery UI version not compatible with the jQuery validation version?
kindly advise.
回答1:
Found it, it was actually trigger by a date method validation in jquery.validate.min.js, which is in line 1356:
// http://jqueryvalidation.org/date-method/
date: function( value, element ) {
return this.optional( element ) || !/Invalid|NaN/.test( new Date( value ).toString() );
},
来源:https://stackoverflow.com/questions/41435873/where-trigger-the-please-enter-a-valid-date-in-jquery-validate-js