I have a basic cordova app, and when the user presses the back button after filling out a form, I want the form to be saved to localstorage and then the back button to route back to the menu. Saving the form is not an issue, I have this working perfectly. However I can't get the functionality to work when the backbutton is pressed.
function init(){
document.addEventListener("deviceready", onDeviceReady, false);
};
This adds for device ready
function onDeviceReady(){
document.addEventListener("backbutton", onBackKeyDown, false);
}
Then I add the back button event
router.addRoute('#basicInformation', function () {
$('body').find("#populate").html(new BasicInformationView().render().$el);
$(":button").click(() => {
handleBasicForm(false);
});
function onBackKeyDown(){
handleBasicForm(true);
}
Then here inside of my route I try and handle the onBackKeyDown function that is fired when the back button is pressed.
However the event is not being fired, am I handling this the correct way?
I want to be able to override the back key functionality on each page, that way I can make sure each form saves correctly, and additional pages are handled properly.