Hello,
I wanted to make a form with buttons. When someone click on a button a radio dialog appear, and when he have finished to choose his answer the button become green, or his answer is written on the button (the one that call doradio() )
I don’t know how to do this, i’m using Ionic v3.2.
Here is my html :
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Urbain</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<h3>Urbain</h3>
<p>
Veuillez remplir votre cas :
</p>
<ion-row>
<ion-col>
<p>Choisir la circulation :</p>
</ion-col>
<ion-col>
<button ion-button block (click)="doRadio()">Three</button>
</ion-col>
<ion-col>
<button ion-button block (click)="validation()">Test valid</button>
</ion-col>
</ion-row>
</ion-content>
And here is my .ts :
import { Component } from '@angular/core';
import { AlertController, NavController } from 'ionic-angular';
@Component({
selector: 'page-urbain',
templateUrl: 'urbain.html'
})
export class UrbainPage {
testRadioOpen: boolean;
testRadioResult;
constructor(public navCtrl: NavController, public alertCtrl: AlertController) {
}
doRadio() {
let alert = this.alertCtrl.create();
alert.setTitle('Lightsaber color');
alert.addInput({
type: 'radio',
label: 'Blue',
value: 'blue',
checked: true
});
alert.addInput({
type: 'radio',
label: 'Green',
value: 'green'
});
alert.addInput({
type: 'radio',
label: 'Red',
value: 'red'
});
alert.addInput({
type: 'radio',
label: 'Yellow',
value: 'yellow'
});
alert.addInput({
type: 'radio',
label: 'Purple',
value: 'purple'
});
alert.addInput({
type: 'radio',
label: 'White',
value: 'white'
});
alert.addInput({
type: 'radio',
label: 'Black',
value: 'black'
});
alert.addButton('Cancel');
alert.addButton({
text: 'Ok',
handler: data => {
console.log('Radio data:', data);
this.testRadioOpen = false;
this.testRadioResult = data;
}
});
alert.present().then(() => {
this.testRadioOpen = true;
});
}
validation(){
alert("La valeur:" + this.testRadioResult);
}
}