Confirmation dialog on closing page

Hi,

I have a page where the user can fill in his data and save. I want to show a confirmation dialog when the user closes the page or navigates to another page and didn’t save yet… (see below) How can I do this in Weweb?

Thank you in advance!

Hi @marciano_antonacci :wave:

I think you might need a little bit of JavaScript for this one to “hear” when the user is navigating away from the page.

Not sure what bit of JS though :sweat_smile: Let me ask a friend and get back to you on that one!

You have before unload right there. Is there a problem with using that?

The scripts doesn’t seem to work like I would expect them to work. When the page is loaded and this script is executed, the warning popup is shown on every page when refreshing or closing the browser, but not when navigating in the application itself. I think this is because of Vue and it’s single page behaviour?
Also I would like to show this popup only when a user changed data on the specific page and it seems like I can’t use application variables in the custom code scripts?

Hey,
here is a quick video explaining how to do it with a Weweb modal and an unload page trigger.
Unfortunatly at the moment you can only delay the navigation, not cancel it, but i opened a ticket about this to our product team.

This video is using the fact that the unload workflow await any async action, so here we create a Promise (js object to wait), and we resolve this promise inside the modal.
It can seems a bit complicated if you are not used to Javascript promise, but these are only two lines of code :).

Here my workflow are just holding the navigation and then let it go, but your workflow inside the modal can do whatever you want (save action for example)

Hope this help!

@aurelie

I have another use case and this was Brilliant!

Cheers!

1 Like

Actually, I found an article on StackOverflow, that might be a nice answer, if you’re willing to code a little.

interesting! thanks

Hi @aurelie - any update from the product team on this? It appears your video is no longer available.

No new concerning the possibility to cancel it, but you can hold it if needed (and run save for example)