Home > OS >  How to set ionic checkbox selected only one?
How to set ionic checkbox selected only one?

Time:09-13

How can only set it only can be select one checkbox only? //below image show current can be select multi checkbox.

//html
<td><ion-checkbox :value="item.cCouponCode" @ionChange="GetCode($event)" checked="false"></ion-checkbox></td>
//typescript
GetCode($event){
this.SelectedVoucherCode = $event.detail.value;
console.log($event);
}

Problem

CodePudding user response:

By adding an ID the elements when doing the loop. Each of those items need an id attached to be able to target specific item.

CodePudding user response:

This is my answer

//typescript
if(this.SelectedList.length >=1){
        $event.target.checked = false;
        alert('You cant selected more than one voucher/ '  'You already selected' this.SelectedList[0].Code);
}
else{
    this.SelectedList.push({'Code':$event.detail.value});
}
//html
<ion-checkbox :value="item.cCouponCode" @ionChange="GetCode($event)" checked="false" :id="index">

enter image description here

  • Related