2016-09-14 71 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!\"> 
相关问题