How to set maximum length for ui-select-match

I use "ui-select-macth" to add multiple values. Is there a way to set the maximum length of the text box that will be entered every time, if so, can you help me?

+1
source share
1 answer

You have a question.

The following is the HTML code:

<div ng-app="ngrepeatSelect" ng-controller="ExampleController">
  <form name="myForm">
    <label for="repeatSelect"> Repeat select: </label>
    <select name="repeatSelect" id="repeatSelect" ng-model="data.repeatSelect">
      <option ng-repeat="option in data.availableOptions" value="{{option.id}}">{{option.name | truncate:3 }}</option>
    </select>
  </form>
  <hr>
  <tt>repeatSelect = {{data.repeatSelect}}</tt><br/>
</div>

Below is the angular js code. I used ui-select match and options with ng-repeat along with the filter.

angular.module('ngrepeatSelect', [])
 .controller('ExampleController', ['$scope', function($scope) {
   $scope.data = {
    repeatSelect: null,
    availableOptions: [
      {id: '1', name: 'Option A'},
      {id: '2', name: 'Option B'},
      {id: '3', name: 'Option C'}
    ],
   };

}])
.filter('truncate', function () {
        return function (text, length, end) {
            if (isNaN(length))
                length = 10;

            if (end === undefined)
                end = "";

            if (text.length <= length || text.length - end.length <= length) {
                return text;
            }
            else {
                return String(text).substring(0, length-end.length) + end;
            }

        };
    });

Click here to go on demonstrating the above code.

+1
source

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


All Articles