[英]How to enable/disable an Ionic >=2 alert button if there are no input selections
我有一个带有单选按钮选项的离子警报,并且想要禁用“确定”按钮,直到用户做出选择。 非常类似于这篇文章 ,除了我想在警报本身的动作上做,并能够更新按钮“启用”,所以我的设置将如下
import { AlertController } from 'ionic-angular';
export class MessageService {
constructor(private alertCtrl: AlertController) {
}
presentAlert() {
let alert = this.alertCtrl.create();
alert.addInput({
type: 'radio',
label: 'Option 1',
value: 'value1',
checked : false
});
alert.addInput({
type: 'radio',
label: 'Option 2',
value: 'value2',
checked : false
});
alert.addButton('Cancel');
alert.addButton({
text: 'Ok',
handler: data => {
}
});
alert.present();
}
}
我希望ok按钮最初被禁用,但是一旦用户做出选择就会启用。 由于离子选择也使用警报,因此能够在那里使用相同的东西会很好。
这可能/有一个简单的方法吗?
在此先感谢您的帮助。
我可能会迟到但这对我有用。
var bool=true;
然后在addInput中
disable:bool
我不知道为什么我必须这样做,但它确实有效。
试试这个。
presentPrompt() {
let alert = this.alertCtrl.create({
title: 'Cancel Prompt',
inputs: [
{
type:'radio',
label:'Cancel for reason 1',
value:'Cancel for reason 1'
},
{
type:'radio',
label:'Cancel for reason 2',
value:'Cancel for reason 2'
}
],
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: data => {}
},
{
text: 'OK',
handler: data => {
if (data) {
console.log(data
} else {
this.presentAlert();
}
}
}
]
});
alert.present();
}
private presentAlert() {
let alert = this.alertCtrl.create({
title: 'Validation select',
subTitle: 'Please select',
buttons: [{
text:'Ok',
handler:data=>{
this.presentPrompt();
}
}]
});
alert.present();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.