For example, a ViewModel will be pre-defined by product team.
Customers can then extend the viewmodel if required to add additional validations in a custom js file or part of html.
5 Answers, 1 is accepted
I posted my reply in the support ticket on the same ticket. For convenience, I am pasting the relevant part below:
To extend a Kendo Model you can use the extend method:
var
baseModel = kendo.data.Model.define({
fields: {
ID: {editable:
false
},
MyNumber: {type:
"number"
}
}
});
var
childModel = baseModel.extend({
fields: {
MyNumber: { validation : { min: 1, max : 1000}}
}
});
var
model = childModel();
Daniel
Telerik
Hi Daniel
I have an old project where we have 2 models we discovered own common fields, after reading your post we selected common fields and methods and pushed up in a commond base model, but application stopped to work, we prepared a sample code
https://dojo.telerik.com/ejAxuPiV/2
The problem is we rely on some fields are nullable == true, after applying suggested changed those fields are equal undefined and they should be null instead, so I think there are a lot of malfunction
In our application we set up datasource via DataSource.create([ ...]) with a list of models that miss fields have a default value nullable, and we want they stay null if are not defined
I have reviewed and researched the issue observed. Nevertheless, I did not manage to isolate the root cause that causes the discussed. We will give another try to that scenario. I will come back to you as soon as I know something more on that matter.
Regards,
Veselin Tsvetanov
Progress Telerik
Hi Veselin, We want to share with Telerik a patch for our specific case and now we can make it works as we wanted :
Model.define =
function
(base, options) {
if
(options === undefined) {
options = base;
base = Model;
}
var
model, proto = extend(
true
,{ defaults: base.defaults || {}, fields: base.fields || {} }, options), name, field, type, value, idx, length, fields = {}, originalName, id = proto.id, functionFields = [];
// ....
// ....
}
In details we added special dealing of fields and defaults property on the base model, they need to be copied onto child model, I hope this could be a worthwhile patch
Thank you for the detailed review of the case and for the suggested solution that would facilitate the scenario in question. Based on that I have created the following item in our backlog. As soon as our priority queue allows it, we will carefully examine the proposal to decide on how to integrate it in the Model.define() implementation.
As a small token of gratitude for helping us improve our code base I have updated your Telerik points.
Regards,
Veselin Tsvetanov
Progress Telerik