When using jQuery UI Datepicker in my asp.net mvc application, I encouter a problem with Google Chrome: If I enter a date with a day higher than 12, it does not accept it as a valid date, and the folowing error message is displayed : "The field Date fin must be a date". I think that this is because chrome thinks the dateformat is mm/dd/yyyy. I tried to overcome this issues by adding the following jquery code on my cshtml page (this solution is proposed on this post : The field date must be a date in mvc in chrome) :
$(document).ready(function () {
jQuery.validator.methods.date = function (value, element) {
var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
if (isChrome) {
var d = new Date();
return this.optional(element) || !/Invalid|NaN/.test(new Date(d.toLocaleDateString(value)));
} else {
return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
}
};
});
But the browser return this error : Cannot read property 'methods' of undefined. Any ideas/suggestions to overcome this issues?
Thanks for your help.