Search
 
SCRIPT & CODE EXAMPLE
 

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;
       
     }
  }
  
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: Make a card dynamic with Angular JS 
Javascript :: Why is this forEach code snippet invalid in AngularJS 
Javascript :: angularjs Both ng-model and ng-change on input alter the $scope state - which one takes priority 
Javascript :: Delete Button not working with json server using angularjs 
Javascript :: angularjs How to get time difference from ZoneDateTime in javascript 
Javascript :: Fire "data-ng-change" programatically or another way to change value of input on website using Angular JS 
Javascript :: Issue in applying margin using angular "data-ng-style" 
Javascript :: Angular.js : recursive call to an $mdDialog controller 
Javascript :: convert base64 formatted data to image using AngularJs 
Javascript :: Changing Component File location in React native does not show in main App 
Javascript :: check if Popups and Redirects are allowed 
Javascript :: change useragent cypress test run 
Javascript :: python regex consecutive characters 
Javascript :: how to set the x and y axis title in plotly express bar 
Javascript :: Streaming search queries with Node.js and Socket.io (streaming to a given socket 
Javascript :: make field un updatable mongoose 
Javascript :: store api key in environment variable ngular 
Javascript :: javascript patterns 
Javascript :: javascript password kodachi 
Javascript :: Bare Minimum Passport Login Pages App.js 
Javascript :: javascript code to decide even or odd number in html using visual studio 
Javascript :: kendo grid column template based on condition 
Javascript :: Create Built-in AbortController Object 
Javascript :: Declare Function To Be Used In Class 
Javascript :: JavaScript get div height dynamically without jQuery 
Javascript :: how to store new object made by constructor classes data in local storage using javascript 
Javascript :: camelcase to css variable javascript 
Javascript :: Backbone Model Fetch 
Javascript :: file path to blob javascript 
Javascript :: c# to javascript object 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =