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

Autoselect when lose focus

1 Answer 183 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Romeu
Top achievements
Rank 1
Romeu asked on 01 Apr 2014, 01:13 PM
Hi, I identified that when using a data source with serverFiltering enabled, while the user is typing something in the input the list of items are being filtered as well, when for example just 2 items remains in the list and the user press the tab button or just click outside making the component loses its focus nothing is selected in the combo. I would like that when the list of items still is open and I loses its focus the first item is auto selected.

I ended up doing something like this:

widget._events.change.push(function (event) {
               var minLength = $(element).attr("data-odata-minlength") || 2;
               var value = widget.value().trim();
               if (value != '' && value.length >= Number(minLength) && widget.dataItem() == undefined && widget._data().length > 0) {
                   var firstItem = widget._data()[0];
                   setTimeout(function () {
                       $.each(widget._data(), function (index, item) {
                           if (item.Id == firstItem.Id) {
                               widget.select(index);
                               return false;
                           }
                       });
                   }, 100);
                    }
           });
I don't like the idead of having a setTimeout function to set the select item but when I simply set the select without using the setTimeout function it works but something triggered after the change/close events resets my alteration and the selectIndex becomes -1.

Any tips?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 02 Apr 2014, 10:43 AM
Hello Romeu,

I answered to the support thread opened on the same subject. Here is a quote of the answer:

I would strongly suggest you use the widget's bind method to attache events. Using a private fields is not safe as they can be renamed in future releases of Kendo UI. I prepared a simple Kendo Dojo demo to show how to select first item if a custom value or an incomplete one has been entered.

I will ask you to continue our conversation in only one thread to avoid any duplication. Thank you for the understanding.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
ComboBox
Asked by
Romeu
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or