1

I am using "ui-select-macth" for adding multiple values. Is there any way to set the maxlength of the text field that to be entered every time,If yes, can you please help me .?

LearnAngular
  • 71
  • 2
  • 8

1 Answers1

1

Ok got your question.

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>

Following 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 to demo of above code.

Avdhut
  • 150
  • 4
  • 15
  • Thanks for you response. But it describes about the number of choices that we can limit .But my question is how to limit the text that we enter on the placeholder – LearnAngular Oct 19 '15 at 14:08