I am trying to make a simple demo of a multiple select option. I also have a limit in my demo. In other words, a user can only select two items.
I am able to do that but when a user selects a third one, a checkbox is selected for the second. Alert is display when I press the ok button then it become unchecked. I would like only the alert to be displayed when a user select third item. here is my code http://codepen.io/anon/pen/NqdmNv
The click button shows a pop up screen. Select "A" and "B" then "C". It shows "c" checked and alert is display when the user presses ok then c becomes unchecked. I only need the alert not "c" to become checked for second.
angular.module('ionicApp', ['ionic'])
.controller('MyController', function($scope, $ionicPopover) {
$scope.MAX=2;
$scope.countMax = 0;
$scope.data =[
{"name":"A", value:false},
{"name":"B", value:false},
{"name":"C", value:false},
{"name":"D", value:false},
{"name":"E", value:false}
]
$ionicPopover.fromTemplateUrl('my-popover.html', {
scope: $scope
}).then(function(popover) {
$scope.popover = popover;
});
$scope.openPopover = function($event) {
$scope.popover.show($event);
};
$scope.closePopover = function() {
$scope.popover.hide();
};
$scope.maxCheck = function($index){
$scope.countMax = 0;
for(i=0;i<$scope.data.length;i++){
if($scope.data[i].value == true)
$scope.countMax++;
}
console.log("CALC",$scope.countMax,$scope.MAX)
if($scope.countMax > $scope.MAX){
$scope.data[$index].value = false;
alert("limit reached");
}
}
}
)