question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ionic 2: Confirm button with role:cancel does not fire on android back button

See original GitHub issue

Short description of the problem:

When presenting an alert since beta 11, if the user presses the Android hardware back button, the role: 'cancel' handler is not fired.

In previous beta versions, this was fired.

What behavior are you expecting?

For the Android back button to fire the handler with role: 'cancel'

Steps to reproduce:

  1. Put the code below on a page linked to a button
  2. Notice that when pressing hardware back button, alert is not fired.
let confirm = this._alertController.create({
        title: 'Do You agree?',
        message: 'Please say whether you agree',
        buttons: [
          {
            role: 'cancel',
            text: 'Disagree',
            handler: () => {
              alert('cancelled')
            }
          },
          {
            text: 'Agree',
            handler: () => {
            }
          }
        ]
});
confirm.present();

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

Which Ionic Version? 1.x or 2.x 2.x

Plunker that shows an example of your issue

Sorry, but I can’t show this in a plunkr as it requires the android hardware button.

Run ionic info from terminal/cmd prompt: (paste output below) Davids-Air:AppHazard daveshirman$ ionic info

Your system information:

Cordova CLI: 6.2.0 Ionic Framework Version: 2.0.0-beta.11 Ionic CLI Version: 2.0.0-beta.32 Ionic App Lib Version: 2.0.0-beta.18 ios-deploy version: 1.8.6 ios-sim version: 5.0.8 OS: Mac OS X El Capitan Node Version: v4.3.0 Xcode version: Xcode 7.2.1 Build version 7C1002

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
daveshirmancommented, Sep 27, 2016

Hello, can someone from the Ionic team please reply to this? @jgw96

1reaction
manucorporatcommented, Dec 7, 2016

@daveshirman it is not a solution, but it is better to disable a buggy feature that can lead to worst scenarios (like a frozen app).

The fix for this issue is not trivial and we are about to release a new version very soon, it is too later for big changes.

From a UX, you are right. But a Alert is a UI element that is asking for user interaction, an alert WANTS the user to do something, so we think disabling the hardware go back is not a big deal from an UX point of view in the meantime.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ionic 2: Confirm button with role:cancel does not fire ... - GitHub
This is a duplicate of bug #7824 I am submitting this simply because no one has ... Ionic 2: Confirm button with role:cancel...
Read more >
Ionic 2: How to handle the hardware back button which checks ...
I am facing an issue how to handle the default mobile's back button which checks the confirmation while exiting from the application ...
Read more >
hardware back button event and confirm by the user to exit ...
hardware back button event and confirmed by the user to exit with Ionic and capacitor app In this Ionic 5/4 + Capacitor tutorial....
Read more >
Hardware Back Button for Capacitor & Cordova on Android ...
When running in a Capacitor or Cordova application, Ionic Framework will emit an ionBackButton event when a user presses the hardware back button....
Read more >
Ionic: How to Simulate Android back button in Browser
When we fire the event, a confirmation dialog is opened. Image 2 — Back button behavior. As you can see although it working...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found