BackButton and Confirm Dialog box

Hi All,

I am trying to implement backButton when pressed confirm from user if he wants to exit the app.

I do not know why the event module not been executed:

$(’.open-confirm’).on(‘click’, function () {
app.dialog.confirm(‘You want to exit the application?’, function () {

    });

The segment of code is not executed and it is not giving any error:

import $ from ‘dom7’;
document.addEventListener(‘deviceready’, function () {
document.addEventListener(“backbutton”, onBackKeyDown, false);

function onBackKeyDown() {

  $('.open-confirm').on('click', function () {
    app.dialog.confirm('You want to exit the application?', function () {
     
    });
  });
 
}

}

Thanks

Thanks Fernando. After rearranging my codes, the below worked:

var dialog = this.$f7.dialog

    .create({

      title: "Quit",

      text:

        "Are you sure you want to quit Application?",

      content: "",

      buttons: [{ text: "No", close: true }, { text: "Yes" }],

      onClick: (dialog, index) => {

        const app = this.$f7;

        if (index == 1) {

          this.$store.commit("setQuitApplication", null);

          this.$f7.dialog.close();

          app.panel.close();

          if (window.hasOwnProperty("cordova")) {

            window.navigator.app.exitApp();

          }

        } else {

          this.$store.commit("setQuitApplication", null);

          this.$f7.dialog.close();

          app.panel.close();

        }

      },

      on: {

        open: function () {

          //console.log("OPEN");

        },

      },

    })

    // console.log("close here2")

    .open();

Thanks

Nice. Good it helps you…

1 Like