Autoselect when lose focus

2 posts, 0 answers
  1. Romeu
    Romeu avatar
    1 posts
    Member since:
    Sep 2013

    Posted 01 Apr 2014 Link to this post

    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) {
                                   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?

  2. Georgi Krustev
    Georgi Krustev avatar
    3689 posts

    Posted 02 Apr 2014 Link to this post

    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.

    Georgi Krustev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top