I have defined kendocombox in my html like below
<input id="selFrameworkVersion" style="width: 210px" data-bind="kendoComboBox: { dataTextField: 'Name', dataValueField: 'Id', data: $root.versionListByProductType, value: $root.editFrameworkVersion, optionsCaption: 'Select Version...' }" />
The combobox loads correctly and sets value but when it doesnt set focus to proper item in list. See image below
You can see value is 5.5.1 but it sets to 5.4 which is first item in list. I now know that why its happening. On my combobox you can see that i have value set as $root.editFrameworkVersion. In my view model i use subscribe event on that value. See code below
self.editFrameworkVersion.subscribe(function (value) {
var combobox = $("#selFrameworkVersion").data("kendoComboBox");
var callback = function (data) {
self.editOnlyAlternativeVersions(self.versionListByProductType());
combobox.select(function (dataItem) {
return dataItem.Name === value;
});
self.editOnlyAlternativeVersions.remove(function (data) {
return parseInt($("#selFrameworkVersion").attr('value')) === parseInt(data.Id());
});
};
loadVersionListByProductType(self.editProductType().Id(), callback);
});
I use this subscribe event to do some logic. In this event i am calling WCF service which loads value again in that combobox and thats why its always set to first value. But its required for me to call that service for some logic. Then i added code in that subscribe event which you already have seen above
combobox.select(function (dataItem) {
return dataItem.Name === value;
});
This code sets the value correctly but only if combobox loses focus. What should i do?
Try something like this $("#selFrameworkVersion").attr("autofocus",true);
In the ComboBox demo here they use an
index
property to set the initially selected item. Not sure if you can try that in your case. Otherwise there is also a .select() method that you can call on the widget to set the selected item.It does seem odd that it doesn't set the selected item based on the
value
. Maybe it is a bug.