I have a Kendo Autocomplete item :
<input type="text" id="Ac_Transporteur" class="" maxlength="30" required/>
--------------------------------------------------------------------------
$("#Ac_Transporteur").kendoAutoComplete({
dataTextField: "Nom",
//Not interesting code here
dataSource: dsTransporteurs,
suggest: true,
delay: 0
});
I have no problem selecting my objects from my datasource dsTransporteur, but I need to get the object that is selected in the autocomplete.
I tried this :
var transp = $("#Ac_Transporteur").data("kendoAutoComplete");
var transpSelect = transp.select();
oVehicule._Transporteur = transp.dataItem(transpSelect);
but transp.select() don't return the index of the object in the datasource and is "undefined".
Any idea how I can get the object selected in my autocomplete ?
I also tried to add a global var named veh_Transporteur and added this :
change: function (e) {
veh_TRANSPORTEUR = this.dataItem();
},
But I still have "undefined" in veh_TRANSPORTEUR.
Try the following
$("#Ac_Transporteur").kendoAutoComplete({
dataTextField: "Nom",
dataSource: dsTransporteurs,
suggest: true,
delay: 0,
select: onSelect
});
function onSelect(e) {
var dataItem = this.dataItem(e.item.index());
alert(dataItem);
}
}