I’ve been trying to implement a dirty form check (ask the user if he really wants to leave the page if the form is dirty) which also works for reload and tab/browser-closing. For this to work I need to add a listener to the javscript beforeunload event afaik.
In short i need a javscript snippet like this:
window.addEventListener('beforeunload', (event) => {
if (formChanged) {
event.returnValue = 'You have unfinished changes! Do you really want to leave?';
}
});
My question is now: how do i get the formChanged from the binder in java into my javscript code?
Hey Simon, I took a look at this and the documentation of the library is not really good I have to say. Can you explan me how to use this only if the binder has changes?
good point. I am using the Guava event bus, so my main concern was removing stale listeners. But out of the box implementation of unload observer for the “you have not saved you will loose your changes” would be very nice.