Hi guys!
I’m doing some short app where there is a page that contains a list of checkboxes.
I want the user to check all the checkboxes in the list before he can move on to the next page (with button).
And if he push the button without checking all the checkboxes, then he got an alert.
To do that, you know we can use the “checked” variable of the checkbox whether it’s true or not (checked or unchecked).
I’m sorry I don’t really understand how it works and honestly I’m bad at programming. Please pardon me!
So, I’m just gonna put my code here and if someone knows how to fix it, then please help me…
Thanks! (I’m still using beta 6 by the way…)
Instruksi.ts
import {Page, NavController, Alert} from 'ionic-angular';
import {InstruksiLastPage} from '../instruksi-last/instruksi-last';
@Page({
templateUrl: 'build/pages/instruksi/instruksi.html',
})
export class InstruksiPage {
constructor(public nav: NavController) {}
public checklists = [
{
title: 'Checklist 1',
checked: false
},
{
title: 'Checklist 2',
checked: false
},
{
title: 'Checklist 3',
checked: false
}
];
goToNextPage() {
if (this.checklists) { //this is supposed to be the code where the app checks if there's still unchecked list. How??
this.doAlert();
} else {
this.nav.push(InstruksiLastPage);
}
}
doAlert() {
let alert = Alert.create({
title: 'Hold on',
message: 'You are not done with your tasks yet!',
buttons: ['Ok']
});
this.nav.present(alert);
}
}
And Instruksi.html
<ion-header>
<ion-navbar>
<ion-title>
Instruksi
</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list>
<ion-list-header>
Instructions
</ion-list-header>
<ion-item *ngFor="#item of checklists">
<ion-label>{{ item.title }}</ion-label>
<ion-checkbox></ion-checkbox>
</ion-item>
<button danger (click)="goToNextPage()">Next</button>
</ion-list>
</ion-content>