2016-09-14 70 views
1

是否有任何已經制作的擴展甚至是angularJS的ui-select(select2主題)的內置選項來顯示用戶輸入更多字符的信息在使用時顯示結果AngularJS ui-select最小輸入長度不告訴用戶輸入更多字符

minimum-input-length=3 

選項?我說的功能,就如同

formatInputTooShort(function() {return "Input more characters!;}); 
jQuery中選擇2

https://select2.github.io/select2/)。

這裏的plunker設置了基本的選擇使用庫版本我用:http://plnkr.co/edit/K9alAMAzvUqCY7Or8RwY?p=preview

我一直在谷歌上搜索了好久了,並一直沒能找到任何現有的解決方案。我不得不使用它們來包含plunker代碼片段。任何幫助或暗示讚賞。

回答

0

我在用戶界面中遇到了類似的問題。我使用angular-ui並將其用於所有我的下拉列表(有幾個)。雖然這不是一個天然的選擇2選擇,角度的用戶界面的下拉列表中,可以使用使用屬性theme="select2"

要在至少3個字符的輸入限制,使下拉菜單,就像選擇2,這裏就是你要做的:

控制器JS:

$scope.limitTitleSearch = 5000; //this should be initialised to more than the number of entries the dropdown holds 
$scope.checkTitle = function(lettersTyped){ 
     if(lettersTyped.length > 2){ 
      $scope.limitTitleSearch = 500; 
     }else{ 
      $scope.limitTitleSearch = 0; 
     } 
    } 

HTML:

使用用於輸入多於3個字符顯示消息。像:

<ui-select-no-choice> 
    Type at least 3 chars for options to load 
</ui-select-no-choice> 

和使用的ui-select-choicesrefresh屬性來調用JS功能。

所以你的HTML看起來

<ui-select-choices 
    refresh="checkTitle($select.search)" 
    refresh-delay="1000" 
    repeat="item in (itemArray | filter: $select.search limitTo: limitTitleSearch) track by item.id"> 
    <span ng-bind="item.name"></span> 
</ui-select-choices> 
//add <ui-select-no-choices code here 

希望這有助於。 :)

+0

有限制最少的用戶輸入長度本地參數,這就是所謂的最小輸入長度,它吃的字符數。我缺乏通過ui-select-no-choice提供的選項。雖然它不是我想達到的,但它與最小輸入長度結合起來可能適用於大多數情況。 – SuperTukan

0

請參見下面的鏈接,類似於你的問題:

https://stackoverflow.com/a/41757481/4434112

但在你的情況下,在用戶界面,選擇plugin.js和編輯模板「選擇2/select.tpl.html 「(對於主題select2)將佔位符更改爲所需的消息

placeholder =」輸入最少3個字符!「

所以在模板將如下所示:

<input type=\"search\" ........... placeholder=\"Input minimum 3 characters!\"> 
相關問題