How to prompt user before close of editor modal?
How to prompt user before close of editor modal?
Hello. I would like to display a prompt to user before close of editor modal.
I've tried attaching to the editor "close" event, but modal closes right away.
editor.on( 'close', function ( e ) {
e.preventDefault();
return confirm( 'Are you sure you want to close?' );
});
Any help greatly appreciated.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
I figured it out! Had to add a cancel button and my own handler to the modal form.
Then I had to hide the close button (x) in the modal header via CSS (SASS) so it wouldn't circumvent the new handler. Maybe there's a better way to do this part--ideas welcome.
Thanks for posting back - that looks good. You could also use the
onBlur
option ofform-options
which is cancellable.Allan