How to use SweetAlert2 in onPreClose event
How to use SweetAlert2 in onPreClose event
This is my code below, as SweetAlert2 is async alert.
It is working to some extent, the editor close already before the preClose
editor.on('preClose', async function (e) {
// On close, check if the values have changed and ask for closing confirmation if they have
if (openVals !== JSON.stringify(Jobeditor_@(item.JobPrimaryID).get())) {
return await editorConfirmAlert("You have unsaved changes. Are you sure you want to exit?", "Are you sure?")
.then(function (result) {
if (result.value) {
return true
} else {
return false
}
});
//i am not using this confirm
//return confirm('You have unsaved changes. Are you sure you want to exit?');
}
})
})
This discussion has been closed.
Answers
The
preCloseevent handler doesn't accept a Promise in the return I'm sorry to say. You'd need to returnfalsefrom it and then callclose()if the user wants to confirm the close (which will triggerpreCloseagain, so you'd need a flag to indicate that it should complete!).Allan