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

Kendo AutoComplete Get Index

2 Answers 557 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 10 Mar 2016, 01:14 PM

hi,

i'm looking for a way to get kendo autocomplete selected index or selected object i have tried this fiddler working fine but  i need to access those properties with button click 

how can i do it

$('button').on('click', function(e){
   var value = $('#autocomplete).data('kendoAutoComplete').value();
});

only i can get this far. is there any other way to get whole object or selected index?

 

2 Answers, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 12 Mar 2016, 04:03 PM
Hello Whey,

You can get the currently selected data item and store it in a global variable in the Kendo UI AutoComplete's select event handler. Then the variable can be used in the button click handler:

var currentlySelectedItem;
   
$("#autocomplete").kendoAutoComplete({
  dataTextField: "Txt",
  dataSource: {
        data: [
            { Txt : "GB1", value: 1 },
            { Txt : "GB2", value: 2 },
            { Txt : "GB3", value: 3 },
            { Txt : "GB4", value: 4 }
        ]
    },
  select: function(e) {
    currentlySelectedItem = this.dataItem(e.item.index());;
  }
});
   
$('button').click(function(){
 console.log(currentlySelectedItem);
  console.log(kendo.stringify(currentlySelectedItem));
})

The selected item cannot be accessed through the value of the input element, because it is a regular DOM element and its value is a string.

Let me know if you need further assistance.

Regards,
Dimiter Topalov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Andrew
Top achievements
Rank 1
answered on 17 Mar 2016, 04:35 AM
Thanks. that worked!!
Tags
AutoComplete
Asked by
Andrew
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or