I have an alertController where the user has to type in the value.
When clicking on ‘Save’, I’m checking if the input value is valid by subscribing to an Observable.
If the value is invalid, I need to prevent closing the alert - if it’s valid, clicking ‘save’ should close the alert.
I know I can prevent closing the alert onclick via ‘return false’, although that doesn’t work when subscribing to an Observable.
Here’s my code:
const alert = await this.alertController.create({
header: 'Input your value',
inputs: [
{
name: 'my_input',
type: 'text',
placeholder: 'Input your value'
}
],
buttons: [
{
text: 'Discard',
role: 'cancel',
cssClass: 'secondary',
handler: () => {
console.log('Confirm Cancel');
}
}, {
text: 'Save',
handler: (alertData) => {
// Check if input value is valid
this.checkValue(alertData.my_input).subscribe(result => {
if (result) {
// We can close the alert because input is valid
} else {
// Do not close alert, instead display error message because input is not valid
}
});
}
}
]
});
await alert.present();
Does anybody know how to solve this?