2017-10-04 72 views
0

我們目前在Angular 4應用程序中使用Kendo UI自動完成功能。 目前我們允許用戶輸入文本,並且在輸入的第一個字符上立即觸發自動完成查找。Kendo UI Autocomplete for Angular 4 - 數據搜索觸發輸入按鍵

我們要求在用戶按下回車鍵前禁用搜索。

有誰知道這是可能的嗎?

在諮詢了關於http://www.telerik.com/kendo-angular-ui/components/dropdowns/autocomplete/的文檔之後,我知道我可以高舉打開的動作並防止默認,或者直到X字符停止查找,但直到按下按鍵。

我猜測on模糊事件可能是可用的。

回答

0

您將需要訪問實際的底層HTML輸入元素並附加一個keydown處理程序,然後執行自定義邏輯以防止內置過濾,直到按下Enter鍵,通過toggle()方法以編程方式打開Popup,並呼籲搜索處理程序中輸入:

ngAfterViewInit(){ 
    this.ac.searchbar.input.nativeElement.addEventListener('keydown', (e) => { 
    if(e.which === 13){ 
     this.enterPressed = true; 
     this.ac.toggle() 
     this.handleFilter(e.target.value) 
    } else { 
     this.enterPressed = false; 
    } 
    }); 
} 

handleFilter(value) { 
    if(this.enterPressed){ 
    this.data = this.source.filter((s) => s.toLowerCase().indexOf(value.toLowerCase()) !== -1); 
    } 
} 

onOpen(e){ 
    if(!this.enterPressed){ 
    e.preventDefault(); 
    } 
} 

EXAMPLE