Model fields not getting initialized

3 posts, 1 answers
  1. Brian Roth
    Brian Roth avatar
    136 posts
    Member since:
    Oct 2005

    Posted 09 Feb Link to this post


     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 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?


  2. Answer
    Rosen avatar
    3214 posts

    Posted 12 Feb Link to this post

    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" });

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Brian Roth
    Brian Roth avatar
    136 posts
    Member since:
    Oct 2005

    Posted 12 Feb in reply to Rosen Link to this post

    Hi Rosen,

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

Back to Top