Get selected value when having label option

2 posts, 0 answers
  1. Dekel
    Dekel avatar
    25 posts
    Member since:
    Jan 2015

    Posted 12 Jun 2015 Link to this post

    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.

     

  2. Plamen Lazarov
    Admin
    Plamen Lazarov avatar
    135 posts

    Posted 15 Jun 2015 Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top