cancel
Showing results for 
Search instead for 
Did you mean: 

Save changes message before navigation

Former Member

As part of our application we would like to notify users when they're attempting to leave a page if there are unsaved changes present. This is easily done for the page's navButton, however we're struggling with a similar implementation for the browser's back button.

By attaching our controller to the HashChanger hashChanged event we can detect the change, however we can't find a way to prevent the navigation from taking place. Neither the event's cancelBubble nor preventDefault methods prevent the change from happening. We've also tried calling stop on the router, but unfortunately to no effect.

Seeing as the Fiori guidelines suggest always implementing such a confirmation dialog I had expected this to be a trivial task. Can someone shed some light on how to reliably implement such a feature? Have we perhaps overlooked something in UI5 that can be used for this?

Accepted Solutions (0)

Answers (1)

Answers (1)

jamie_cawley
Advisor
Advisor
0 Kudos

How about this?

http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ev_onbeforeunload

Regards,

Jamie

SAP - Technology RIG

Former Member
0 Kudos

Unfortunately beforeunload only fires when the user actually navigates away from the entire page. Routing in UI5 uses hashes for navigation which do not trigger this event.

jamie_cawley
Advisor
Advisor
0 Kudos

If you are using the fiori launchpad there's a service you may be able to use.

Implementing Data Loss Protection - User Interface Add-On for SAP NetWeaver - SAP Library

There's an error in the docs, call should be..

sap.ushell.Container.setDirtyFlag(true);

Regards,

Jamie

SAP - Technology RIG