如何检测用户何时至少打开和关闭 select 一次
How to detect when a user has opened and closed the select at least once
我在表单中使用 IonSelect
来验证用户是否已经 select 编辑了一些东西(它最初是空白的)
我正在为所有表单控件使用通用 blur
处理程序,我在其中检查以下内容:
if (c.dirty || c.touched) && c.errors)
setValidationError()
其中c是控件。
select 的问题是,当显示选项对话框时,我们得到模糊事件以及 select 控件的 c.touched
,所以我马上得到在用户更改 select.
之前显示我的错误消息
我想推迟显示这个,直到 select 打开一次,然后在没有 selection 的情况下关闭(例如取消)。当然如果用户selects something,则不会出现验证错误。
有谁知道我如何知道 select 何时打开然后关闭?我尝试了 oncancel
和许多其他事件,但其中 none 发生了。
您可以像下面这样使用ionCancel
:
在 .html 文件中:
<ion-select [(ngModel)]="gaming" (ionCancel)="cancelSelect()">
<ion-option value="nes">NES</ion-option>
<ion-option value="n64">Nintendo64</ion-option>
<ion-option value="ps">PlayStation</ion-option>
<ion-option value="genesis">Sega Genesis</ion-option>
<ion-option value="saturn">Sega Saturn</ion-option>
<ion-option value="snes">SNES</ion-option>
</ion-select>
<label *ngIf="isGamingTouched && gaming == undefined" color="red" >
show your validation message
</label>
在 .ts 文件中
public gaming: any;
public isGamingTouched: boolean = false;
constructor(public navCtrl: NavController) {
}
cancelSelect(){
console.log(this.gaming);
this.isGamingTouched = true;
}
我在表单中使用 IonSelect
来验证用户是否已经 select 编辑了一些东西(它最初是空白的)
我正在为所有表单控件使用通用 blur
处理程序,我在其中检查以下内容:
if (c.dirty || c.touched) && c.errors)
setValidationError()
其中c是控件。
select 的问题是,当显示选项对话框时,我们得到模糊事件以及 select 控件的 c.touched
,所以我马上得到在用户更改 select.
我想推迟显示这个,直到 select 打开一次,然后在没有 selection 的情况下关闭(例如取消)。当然如果用户selects something,则不会出现验证错误。
有谁知道我如何知道 select 何时打开然后关闭?我尝试了 oncancel
和许多其他事件,但其中 none 发生了。
您可以像下面这样使用ionCancel
:
在 .html 文件中:
<ion-select [(ngModel)]="gaming" (ionCancel)="cancelSelect()">
<ion-option value="nes">NES</ion-option>
<ion-option value="n64">Nintendo64</ion-option>
<ion-option value="ps">PlayStation</ion-option>
<ion-option value="genesis">Sega Genesis</ion-option>
<ion-option value="saturn">Sega Saturn</ion-option>
<ion-option value="snes">SNES</ion-option>
</ion-select>
<label *ngIf="isGamingTouched && gaming == undefined" color="red" >
show your validation message
</label>
在 .ts 文件中
public gaming: any;
public isGamingTouched: boolean = false;
constructor(public navCtrl: NavController) {
}
cancelSelect(){
console.log(this.gaming);
this.isGamingTouched = true;
}