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

Breaking change in dropdownlist 2015.1.408

2 Answers 50 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Mathieu
Top achievements
Rank 1
Mathieu asked on 12 Apr 2015, 10:34 AM

Hello,

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:

@(Html.Kendo().DropDownList()
                  .Name("ddlExercise")
                  .DataTextField("Description")
                  .DataValueField("Id")
                  .OptionLabel("(Kies een oefening)")
                  .DataSource(source =>
                  {
                      source.Read(read =>
                      {
                          read.Action("GetExercises", "Exercise")
                              .Data("filterExercises");
                      })
                          .ServerFiltering(true);
                  })
                  .Events(events =>
                  {
                      events.Select("ddlExercise_select");
                      events.DataBound("ddlExercise_databound");
                  })
                  .HtmlAttributes(new { style = "width:300px" })
                  .Enable(false)
                  .AutoBind(false)
                  .CascadeFrom("ddlCourseLessonGroup")
                )

 

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;

            getExerciseDetailsAndInitialize();

        }

 

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 Answers, 1 is accepted

Sort by
0
Mathieu
Top achievements
Rank 1
answered on 12 Apr 2015, 10:35 AM
For you information, the previous version I was running was 2015.1.318, where this problem did not yet occur.
0
Georgi Krustev
Telerik team
answered on 14 Apr 2015, 01:07 PM
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.

Regards,
Georgi Krustev
Telerik
 

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

 
Tags
DropDownList
Asked by
Mathieu
Top achievements
Rank 1
Answers by
Mathieu
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or