【问题标题】:ui select angularjs set maxlength for input value (ui select match)ui select angularjs 为输入值设置 maxlength(ui 选择匹配)
【发布时间】:2017-02-06 01:07:07
【问题描述】:

我想要一个额外的属性,就像“占位符”从 ui 选择匹配中传递一样。我想设置选择输入的最大长度。我可以通过 select.min.js 添加属性 maxlength="" 来设置它,但我认为对 lib 进行更改。文件不是解决方案。

Just like i have adde maxlength="500" in input

请帮帮我。

谢谢

【问题讨论】:

  • 如果我理解正确,这就是您想要实现的目标(查看下拉菜单)john-oc.github.io

标签: javascript angularjs ui-select ui-select2 angular-ui-select


【解决方案1】:

您可以使用 Angular 的 limitTo 过滤器来限制您的收藏。查看limitTo 参考。

【讨论】:

  • 我不想要下拉菜单的最大长度。我想为该搜索框实现 maxlength ,该搜索框将该值从下拉列表中搜索。希望你现在有我的问题?
【解决方案2】:

据我了解,您正在使用带有标记的 ui-select(作为组合框)。

在此实现你想要的功能:

转到 ui-select plugin.js 并编辑模板“select2/select.tpl.html”(用于主题 select2):

ng-attr-maxlength="{{$select.tagging.isActivated ? 50 : ''}}"

将以上行添加到模板中,如下所示:

<input type=\"search\" ........... ng-attr-maxlength=\"{{$select.tagging.isActivated ? 500 : ''}}\">

如果你想限制输入搜索本身,那么直接添加 maxlength 属性:

<input type=\"search\" ........... maxlength=\"500\">

希望这会有所帮助。 :-)

【讨论】:

    【解决方案3】:

    你可以通过templateCache改变属性

    .run(function($templateCache) {
            $templateCache.put("bootstrap/select-multiple.tpl.html","<div class=\"ui-select-container ui-select-multiple ui-select-bootstrap dropdown form-control\" ng-class=\"{open: $select.open}\"><div><div class=\"ui-select-match\"></div><input maxlength='5' type=\"search\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" class=\"ui-select-search input-xs\" placeholder=\"{{$selectMultiple.getPlaceholder()}}\" ng-disabled=\"$select.disabled\" ng-click=\"$select.activate()\" ng-model=\"$select.search\" role=\"combobox\" aria-expanded=\"{{$select.open}}\" aria-label=\"{{$select.baseTitle}}\" ng-class=\"{\'spinner\': $select.refreshing}\" ondrop=\"return false;\"></div><div class=\"ui-select-choices\"></div><div class=\"ui-select-no-choice\"></div></div>");
        })
    

    原始模板可以在文件 select.js 的底部找到

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-05
      • 1970-01-01
      相关资源
      最近更新 更多