2014-01-06 27 views
0

我有一個頁面,使用KendoUI控件與淘汰賽的綁定,我需要使用Enter而不是Tab來瀏覽控件。使用輸入作爲選項卡與淘汰賽綁定和KendoUI下拉

我設法使其使用here發佈該解決方案通過Damien Sawyer,並增強其按住Shift鍵並輸入工作帶來極大的Andre Van Zuydam

ko.bindingHandlers.nextFieldOnEnter = { 
    init: function (element, valueAccessor, allBindingsAccessor) { 
     j$(element).on('keydown', 'input, select', function (e) { 
      var self = j$(this) 
       , form = j$(element) 
       , focusable 
       , next 
      ; 
      var tabElements = 'input,a,select,button,textarea'; 
      if (e.shiftKey) { 
       if (e.keyCode === 13) { 
        focusable = form.find(tabElements).filter(':visible'); 
        prev = focusable.eq(focusable.index(this) - 1); 

        if (prev.length) { 
         prev.focus(); 
        } else { 
         form.submit(); 
        } 
       } 
      } 
      else 
      if (e.keyCode === 13) { 
       focusable = form.find(tabElements).filter(':visible'); 
       var nextIndex = focusable.index(this) === focusable.length - 1 ? 0 : focusable.index(this) + 1; 
       next = focusable.eq(nextIndex); 
       next.focus(); 
       return false; 
      } 
     }); 
    } }; 

的建議(我的代碼使用Ĵ$,而不是$ jQuery的,因爲項目也使用mootools和我重新定義jQuery爲j $)

但是,我有一個kendoui DropDown列表的問題。它不是或元素的問題,所以它不會獲得焦點(相反,它是一個具有特殊類和unselecteable =「on」屬性的跨度)。

我應該如何更新ko綁定代碼以將焦點設置爲Enter下拉?它與標籤

感謝

+0

這聽起來像你需要定製有點對劍道降了下來。你可以發佈你的代碼看起來像當前,也許創建一個[小提琴](http://jsfiddle.net)? – Goose

+0

是的,但我不知道該怎麼做。我用代碼更新了帖子,並鏈接到原始答案,我從中獲得瞭解決方案 – bzamfir

回答

1

做盡我所能,而無需一個劍道樣品,我可以測試了這一點,但我認爲你應該能夠做到這一點。當Kendo創建一個下拉菜單時,正如您所說的那樣,它添加了一堆其他元素,並且沒有像常規選擇元素那樣給定焦點。你可以找到一個劍道選擇,但是,首先找到它的父類跨度爲k-dropdown

嘗試增加k-dropdowntabElements爲一類選擇:

var tabElements = 'input,a,select,button,textarea,.k-dropdown'; 

然後,在您通過添加一個條件,以檢查劍道下拉給予重點調整的一部分。因此,而不是僅僅這一點:

prev.focus(); 

嘗試是這樣的:

if (prev.hasClass('k-dropdown')) { 
    prev.children('select').first().data("kendoDropDownList").focus(); 
} else { 
    prev.focus(); 
}