How to set maximum length for input search in ui-select component (AngularJS)?

Suppose I have the following (very simple) code for ui-select

<ui-select ng-model="vm.selected">
    <ui-select-match>
        <span ng-bind="$select.selected.label"></span>
    </ui-select-match>
    <ui-select-choices repeat="item in vm.items">
        <span ng-bind="item.label"></span>
    </ui-select-choices>
</ui-select>

Now it generates all the html nodes, etc. that contain the input for searching and filtering the parameters displayed in the list.

Problem :

How to set (in any case) the maximum length for input search?

The directive does not offer any built-in data attribute for this.

, : 10 , / + , , (, , , )

SO, , , ng-model .

+4
1

ui-select, input.ui-select-search , , html maxlength... (PLUNKER)

HTML

<ui-select ng-model="vm.selected" maxlen="15">
    <ui-select-match>
        <span ng-bind="$select.selected.label"></span>
    </ui-select-match>
    <ui-select-choices repeat="item in vm.items">
        <span ng-bind="item.label"></span>
    </ui-select-choices>
</ui-select>

app.directive('maxlen', function() {
  return {
    restrict: 'A',
    link: function(scope, element, attr) {
      var $uiSelect = angular.element(element[0].querySelector('.ui-select-search'));
      $uiSelect.attr("maxlength", attr.maxlen);
    }
  }
});

, , , , ui-select , yourserf...

+5

Source: https://habr.com/ru/post/1672298/


All Articles