Breaking change in dropdownlist 2015.1.408

3 posts, 0 answers
  1. Mathieu
    Mathieu avatar
    21 posts
    Member since:
    Feb 2014

    Posted 12 Apr 2015 Link to this post


    I upgraded today to the MVC wrappers 2015.1.408 (I came from just the previous version, so really not far off).

    But I encountered a breaking change I think.

    I am using this dropdownlist:

                      .OptionLabel("(Kies een oefening)")
                      .DataSource(source =>
                          source.Read(read =>
                              read.Action("GetExercises", "Exercise")
                      .Events(events =>
                      .HtmlAttributes(new { style = "width:300px" })


    and in the ddlExercise_select event, I had this:

    function ddlExercise_select(e) {
                var dataItem = this.dataItem(e.item.index());

                exerciseType = dataItem.Type;
                exerciseId = dataItem.Id;




    However, this now raised an issue that the first item in the dropdown list (apart from the optionlabel) would never have the "dataItem" variable defined. Other elements worked without a problem, but the first one did not. If I removed the optionlabel, it worked too.

    In the end, what was able to solve this was to assign the dataitem as var dataItem = this.dataItem(e.item);

    So basically dropping the ".index()".

    Could you please confirm this is indeed a breaking change in 2015.1.408 and that dropping the ".index()" is the correct way to resolve this ?

    Thank you

  2. Mathieu
    Mathieu avatar
    21 posts
    Member since:
    Feb 2014

    Posted 12 Apr 2015 Link to this post

    For you information, the previous version I was running was 2015.1.318, where this problem did not yet occur.
  3. Georgi Krustev
    Georgi Krustev avatar
    3725 posts

    Posted 14 Apr 2015 Link to this post

    Hello Mathieu,

    Indeed, in Q1 2015 we introduced a breaking change related to optionLabel rendering. This change is documented here: Now it is rendered as a header and it is not part of the items list. Hence the e.item.index() will not return the correct index, because the first LI element will have index '0', but its actual index in the dataItems list is '1'.

    The best way to avoid the index calculation is to pass the jQuery element (e.item) as an argument. The method will calculate the correct index internally. Please note that the 2015.1.408 version has a limitation (cannot return a dataItem for OptionLabel element), which is already addressed and it will be included in the next internal build.

    Georgi Krustev

    See What's Next in App Development. Register for TelerikNEXT.

Back to Top