Notice: The Monaca & Onsen UI Community Forum is shutting down.

For Onsen UI bug reports, feature requests and questions, please use the Onsen UI GitHub issues page. For help with Monaca, please contact Monaca Support Team.

Thank you to all our community for your contributions to the forum. We look forward to hearing from you in the new communication channels.

Cancel prepop event shows an error



  • Hi,
    I’m using onsenui v2.0.4, angular 1 and Chrome. I was trying to cancel the prepop event to show a confirmation dialog, i tested with the next code:

            app.navi.on('prepop', function(event) {
                  console.log('Inside the prepop event');
                  event.cancel();    
            });
    

    Seems like the event is cancelled but the next error is showed in the console:
    0_1481726333730_upload-ecc20111-906b-4709-9225-87e1b03d1cb6

    Any ideas anyone?

    Thank you for your help.


  • Onsen UI

    @nataly_g_ That’s just a rejected promise. Methods in Onsen UI return promises and you can handle them like this:

    myNavigator.popPage()
      .then(function() { console.log('previous page'); })
      .catch(function() { console.log('it was canceled'); });
    

    It’s not important since you are the one causing it (it’s not an internal error). If you want to get rid of it just handle it with catch. If you are using an ons-back-button, you can overwrite its behavior with onClick property:

    document.querySelector('#my-back-button').onClick = function() {
      document.querySelector('#myNavigator').popPage().catch(function() {});
    };
    


  • Thanks Fran for your help.

    I’m using the ons-back-button and i tried to overwrite onClick event as in your example but it doesn’t work. I used the simple code to test:

    document.querySelector('#backButton').onClick = function() {
        console.log('Clicking on back button');
    }
    

    The popPage is done but it didn’t enter in the onClick function.

    Do you have any idea? Thanks.


  • Onsen UI

    @nataly_g_ Just make sure your back button is there and that you are changing the correct back button. If you are using 2.0.x it should work.