Custom widget array value in options not being set as expected

3 posts, 1 answers
  1. Brian Vallelunga
    Brian Vallelunga avatar
    103 posts
    Member since:
    May 2008

    Posted 18 May 2012 Link to this post

    I have a custom widget that receives options. On of the options is an array of strings. By default the array value in the options, as defined in my widget, has six values. When instantiating the widget, the end user can supply his own array to override these values. Instead of replacing the entire array, each value passed replaces the default value, leaving a total of six still, even if only one value is passed.

    Here's some pseudocode:

    // Defined in the widget as defaults
    options: {
        intervals: ["Day", "Month", "Quarter", "Year"]
    }
      
    // Later, when creating my widget
    $("#widget").kendoMyWidget({
        intervals: ["Month"]
    });

    What I would expect is that after calling Widget.fn.init.call(that, element, options) in my widget, that options.intervals array would only contain "Month". Instead it contains: "Month", "Month", "Quarter", "Year". Any thoughts on this?

  2. Answer
    Petyo
    Admin
    Petyo avatar
    2444 posts

    Posted 19 May 2012 Link to this post

    Hello,

    This is how jQuery extend(deep) (which kendo uses) method works. 

    $.extend(true, { foo: ['foo', 'bar'] }, {foo: ['bar'] }).foo; // 'bar', 'bar'

    Greetings,
    Petyo
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Brian Vallelunga
    Brian Vallelunga avatar
    103 posts
    Member since:
    May 2008

    Posted 21 May 2012 Link to this post

    Interesting, thanks. I've had to just manually set the options in code after the initialization is done. Easy enough of a workaround, but I'm surprised at the default behavior.
Back to Top