Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

AngularJS ui-select multiple should show alert if limit is crossed

$scope.changed = function(val) {
      if(val && val.length > 2) {
       val.pop();
In context:

app.controller('DemoCtrl', function ($scope, $http, $timeout, $interval) {
  $scope.people = [
    { name: 'var1',      type: 'header' },
    { name: 'var2',  type: 'site' },
    { name: 'var3',  type:'header' },
    { name: 'var4',  type:'header' }
  ];
  $scope.changed = function(val) {
      if(val && val.length > 2) {
       val.pop(); // <- add this line
       $scope.myModel = $scope.prevModel;
       alert("Upto 2 variables can be selected")
     } else {
       $scope.prevModel = val;
       
     }
  }
  
});
 
PREVIOUS NEXT
Tagged: #AngularJS #multiple #show #alert #limit #crossed
ADD COMMENT
Topic
Name
1+2 =