This is a migrated thread and some comments may be shown as answers.

Model fields not getting initialized

2 Answers 51 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brian Roth
Top achievements
Rank 1
Brian Roth asked on 09 Feb 2016, 10:16 PM

Hello,

 I'm running into an issue where the default values configured on a model are not getting set up if arguments are provided to the constructor. Creating a new model without providing any arguments appears to work just fine. However, it appears that the model skips initializing its fields and default values arguments are provided. See http://dojo.telerik.com/aLOZe for a quick example of this behavior.

 Is there some way to get around this other than by making sure to provide values for all fields?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 12 Feb 2016, 09:59 AM

Hello Brian,

The behavior you have described is by design. The default values are used only when Model instance is created without passing initialization data. The purpose of the default values is to be used when creating new empty Model instances. Thus, when passing initial data it is assumed that the intention is to wrap already existing data and no default values will be applied. This assumption also acts as performance optimization as in this case the expensive merging is skipped in the most common case - wrapping existing data.

In order to workaround this you may consider using the accept method passing the partial data, similar to the following:

var someValues = new type();
someValues.accept({ "string": "test" });

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Brian Roth
Top achievements
Rank 1
answered on 12 Feb 2016, 03:48 PM

Hi Rosen,

Thanks for the response. Using the accept function will work perfectly.

Tags
General Discussions
Asked by
Brian Roth
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Brian Roth
Top achievements
Rank 1
Share this question
or