Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic : Prevent alert auto dismiss when clicked on 'OK'

Clicking on 'OK' automatically dismisses the alert. I want to add some logic inside 'OK' click handler and then decide if I want to dismiss the alert or not.

let inputsAlert = this.alertCtrl.create({
    ...
    buttons: [
        {
            text: 'OK',
            handler: inputsData => {

                // Some logic here

                if (canDismiss) {
                    this.inputsAlert.dismiss();
                } else {
                    // Do nothing
                }
            }
        }
    ]
})
like image 501
Mehdiway Avatar asked Jan 25 '23 22:01

Mehdiway


1 Answers

In the array of buttons, each button includes properties for its text, and optionally a handler. If a handler returns false then the alert will not automatically be dismissed when the button is clicked.

From https://ionicframework.com/docs/api/alert#buttons

Simply return false if you do not want the alert to be dismissed.

like image 184
Wei Seng Tan Avatar answered Feb 05 '23 14:02

Wei Seng Tan