Ion-checkbox limit the number of maximum checked boxes


#1

Hello, on ion-checkbox how can we limit the number of maximum checked boxes to 5?

This mean the other box will not be able to be checked unless the user deselect a box.

We need the code if possible thanks.

We tried this:
<ion-checkbox [(ngModel)]=“lst.checked” (ionChange)=“handleOnCheckEvent(lst2)”>

handleOnCheckEvent(lst){
//arry contain the cheked element
if( this.arry.length > 5 ){
lst.checked=false;
}
}

It’s not a good solution us it let the user select the box and than deselect it .


#2

You will have to code this functionality in Angular, as it is not a function of the checkbox component.


#3

Of corse i coded it but there is bug on it, it work for the first click and then it stop working correctly.


#4

hi @forevermo , I’ve got the same problem , do you solved it ?


#5

Hi, no right now there is no solution with native ionic.
The solution: hard coded it, i changed the way how it work with HTML and TypeScript