mardi 26 janvier 2021

keep the checkbox checked after refresh

I want to keep the list of checkboxes that I have checked when I refresh the page or move to another one.

This is my component.ts :

 isValidForm = false;
 public selectedActivityType: any[] = [];
 public assignmentFor: any = [{name :"Cause", id : "t1"}, {name: "Resulted damage", id:"t2"},{ name: "Emergency", id:"t3"}]
 constructor(){}
 ngOnInit(){}
selectActivityFor(event:any, option:any)
 {
  if ( event.target.checked )
   {
     this.selectedActivityType.push(option.id);
   }
 else{
    this.selectedActivityType.splice(this.selectedActivityType.indexOf(option.id),1);
  }    
 if(this.selectedActivityType.length >0 && 
(this.selectedActivityType.indexOf(this.assignmentFor[1].id) !== -1 || 
this.selectedActivityType.indexOf(this.assignmentFor[0].id) !== -1 ) )
 {
  this.isValidForm = true
}
else 
this.isValidForm = false;
 }

This is my component.html :

  <div *ngIf="assignmentFor.length !==0">
          <div class="container-fluid items-container" style="margin-top: 10px">
            <h5 class="mt-3" style="color : rgb(136,136,139); font-weight: bold">
              assignmentFor</h5>
            <div class="row">
              <div *ngFor="let option of assignmentFor; let i=index" class="animated cedfadeInUpX">
                <input type="checkbox" id="activityFor" (change)="selectActivityFor($event, option)" 
                 kendoCheckBox />
                <label class="k-checkbox-label"
                  style="padding-top:10px;margin-left:5px; padding-left:0;font-size: 14px; padding-right: 60px;"></label>
              </div>
            </div>
          </div>
        </div>



Aucun commentaire:

Enregistrer un commentaire