Reputation: 35873
I am trying to extend kendo.ui.validator (similar to jQuery validator) I am overriding the date function, but I should overload the mvcdate function with the very same logic. The overrided date function is called and runs correctly.
I would not like to copy and paste so trying to call the overrided data function from the mvcdata override, with no success. The syntax is this.rules.date(input)
I am totally beginner in javascript OOP part so I have no idea what I am doing, although my syntax seems to be reasonable. What am I missing?
(function ($, kendo) {
$.extend(true, kendo.ui.validator, {
rules: {
date: function (input) {
if (input.is("[data-val-date]")) {
var value = input.val();
var check = false;
//var m = moment(value.toString(), "YYYY-MM-DD HH:mm:ss", true);
var m = moment(value.toString(), defaultJavaScriptDateFormat, true);
check = m.isValid();
//var message = "";
//if (!check) {
// message = "Invalid " + m.invalidAt() + ". Please enter a correct date";
//}
//input.attr("data-val-date", message);
return !input.is("[data-val-required]") || check;
}
return true;
},
mvcdate: function (input) {
// Here I try to call the overrided date function to prevent copy and paste, this cause runtime error in chrome:
return this.rules.date(input);
}
},
messages: {
date: function (input) {
return input.attr("data-val-date");
}
}
});
})(jQuery, kendo);
Upvotes: 0
Views: 75
Reputation: 990
You can access your function using direct method call:
mvcdate: function (input) {
return kendo.ui.validator.rules.date.call(this, input);
}
If kendo.ui.validator
is an instance of an object created using new
keyword and your date
function is the part of prototype you can call it using prototype:
mvcdate: function (input) {
return kendo.ui.validator.prototype.rules.date.call(this, input);
}
Upvotes: 1