Initialization of kendo.data.model does not parse fields:
but setters parse fields:
So I have defined a subclassed model as follows:
The same applies to Model.accept, which does not parse fields either.
Is this a fix you would not recommend (any side effects)?
Is there an alternative use of the api that should be preferred?
Otherwise, is this something that could be fixed in Kendo UI?
var BadModel = kendo.data.Model.define({ id: 'id', fields: { id: { type: 'string', }, date: { type: 'date', } } }), now = new Date(), badObject = new BadModel({ id: '1234567890', date: now.toISOString() });expect(badObject).to.have.property('date').that.is.a('string'); //Mocha testbut setters parse fields:
badObject.set('date', now.toISOString()); expect(badObject).to.have.property('date').that.is.an.instanceof(Date); //Mocha testSo I have defined a subclassed model as follows:
var FixedModel = Model.define({ ... init: function(data) { var that = this; $.each(Object.keys(data), function(index, key) { if ($.type(that.fields[key]) === 'object') { data[key] = that._parse(key, data[key]); } }); Model.fn.init.call(that, data); }});The same applies to Model.accept, which does not parse fields either.
Is this a fix you would not recommend (any side effects)?
Is there an alternative use of the api that should be preferred?
Otherwise, is this something that could be fixed in Kendo UI?