I have an application which allows the customer to set the date format by setting screen. I change the current thread culture date format, and set the date and parsing format in the kendo date picker.
DateTimeFormatInfo datetimeFormat = new DateTimeFormatInfo();
datetimeFormat.FullDateTimePattern = "MM.dd.yyyy hh:mm tt"; //(set static for testing)
Thread.CurrentThread.CurrentCulture.DateTimeFormat = datetimeFormat;
My problem is when I change the date format a client side validation error returns says that the field should be a date. I tried to set custom rule in the kendo validator but that not helps me because when I change the date this rule not fired.
$("myForm").kendoValidator(
{
rules: {
dateValidation: function(input)
{
if (input.is("[data-role=datepicker]")) {
// My code should be here
}
return true;
}
}});
Anyone can help me to solve this issue.
There is no need to add custom rule you need to set the custom format in the kendo validator as following:
kendo.ui.validator.rules.mvcdate = function (input) {
return input.val() === "" || kendo.parseDate(input.val(), "dd/MM/yyyy") !== null;
}
This code will return true (valid) if the date picker has a value and the value is in the correct format (dd/MM/yyyy in the above)