jeudi 28 avril 2016

how to restrict the uncheck of last checkbox using angular js?

i have a list containing checkboxes i want to specify a condition where user can select maximum 5 checkboxes if he tries to select the 6th box a popup should be shown as max count reached , similarly one checkbox should always be selected when user tries to deselect the only left checkbox again their should be a popup than min count reached .

my html :

<div ng-show="isFilterOpen" class="filterDiv1">
            <div class="filterTitle">Select any 5 from the list <br> Currently Selected.</div>
            <div class="checkValue">
                <ion-checkbox ng-repeat="item in unfilteredLabel" ng-model="item.value" ng-checked="item.value" ng-disabled="(clicked && !item.value)" ng-change="selectField(item.label,item.value)">
                    
                </ion-checkbox>
            </div>
            <br>
            <div class="solidLine"></div>
            <br>
            <button class="done" ng-click="callRePaint()">Done</button>
        </div>

my controller code:

$scope.selectField = function(label , value) {
            count = 0;
            for (i = 0; i < $scope.unfilteredLabel.length; i++) {
                if($scope.unfilteredLabel[i].label == label){
                    //$scope.unfilteredLabel[i].value = false;
                }

                if ($scope.unfilteredLabel[i].value) {

                    count++; //count variable contains the number of fields selected
                    console.log(count);

                }

            }
            $scope.filterRemCount=count;
            if (count > (isSmallScreen?1:4)){
                $scope.clicked = true;
                //alert("cannot select more than 5");
            } else {
                $scope.clicked = false;
            }   

             CreatorTableRecord.setcheckedvalue($scope.unfilteredLabel);
            FullTableRecord.setcheckedvalue($scope.unfilteredLabel);

        }

how should i specify the condition to show the popup when count reaches max or min and when count shows min value the last checkbox should be restricted for deselection after showing the popup




Aucun commentaire:

Enregistrer un commentaire