gpt4 book ai didi

angular - 警报 Controller 输入框验证

转载 作者:太空狗 更新时间:2023-10-29 17:08:40 25 4
gpt4 key购买 nike

如何在 Ionic 2 或 3 的 Alert Controller 中验证和显示输入错误

let prompt = Alert.create({
title: 'Alert input validation',
message: "How can I validate below input field?",
inputs: [
{
name: 'email',
placeholder: 'email'
},
],
buttons: [
{
text: 'Save',
handler: data => {
let validateObj = this.validateEmail(data);
if (!validateObj.isValid) {
alert(validateObj.message);
return false;
} else {
//make HTTP call
}
}
}
]
});

有些人已经更新了 alertcontroller 并为 Ionic 团队提出了拉取请求。我认为 Ionic 团队计划在未来实现这一点。 https://github.com/ionic-team/ionic/pull/12541

我需要为此验证功能做一些变通。

plnkr http://plnkr.co/edit/IBonfBJngky0h8UtMwMD?p=preview

感谢您的帮助。

最佳答案

目前这个功能还没有实现,可以看this Git issue .

我在这里使用了 Toast 通知,我的客户对此没有任何投诉:)

这是我所做的。

警报框的 done 处理程序:

{
text: 'Done',
handler: (data) => {
if (EmailValidator.isValid(data.email)) {
if (this.data) {
//my code
} else {
//my code
}
return true;
} else {
this.showErrorToast('Invalid Email');
return false;
}
}
}

toast 方法是这样的:

showErrorToast(data: any) {
let toast = this.toastCtrl.create({
message: data,
duration: 3000,
position: 'top'
});

toast.onDidDismiss(() => {
console.log('Dismissed toast');
});

toast.present();
}

用户界面

enter image description here

关于angular - 警报 Controller 输入框验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45969821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com