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

Get selected value when having label option

1 Answer 485 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Dekel
Top achievements
Rank 1
Dekel asked on 12 Jun 2015, 09:53 PM

I'm using Kendo().DropDownList() with OptionLabel configured.

When trying to get selected item Text / Value, I'm getting incorrect values.

for example if I choose the first drop down option I'm getting the value of the option label.

if I choose the second option I'm getting the values of the first option.

 

@(Html.Kendo().DropDownList()
            .Name("SelectedSubjectId")
            .DataTextField("Text")
            .DataValueField("Value")
            .Filter("contains")
            .OptionLabel("Select Subject")
            .BindTo(Model.MailSubjectList)
            .Events(events =>
                    {
                        events.Select("onSelect");
                    })
        )

Javascript:

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

     // or even

    var selectedValue = this.value()

    var selectedText = this.text()

};

 

How can I get the correct selected value (Text / Value) ?

 

Thank you.

 

1 Answer, 1 is accepted

Sort by
0
Plamen Lazarov
Telerik team
answered on 15 Jun 2015, 01:57 PM

Hello Dekel,

 

Due to a change in the DropDownList rendering the optionLabel is moved outside the items list and placed as a static header on top of the popup element. Since option label element and list items are positioned in different containers the jQuery index method might cause an incorrect behavior. 

 

To make it work use the code snippet below without the .index() method: 

 

var item = this.dataItem(e.item);

Please find below a sample demo illustrating this approach. 

http://dojo.telerik.com/@c0re/omUjU

 

Regards,

Plamen Lazarov

Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DropDownList
Asked by
Dekel
Top achievements
Rank 1
Answers by
Plamen Lazarov
Telerik team
Share this question
or