How to use SweetAlert2 in onPreClose event
How to use SweetAlert2 in onPreClose event
aftab ahmed
Posts: 5Questions: 2Answers: 0
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?');
}
})
})
Answers
The
preClose
event handler doesn't accept a Promise in the return I'm sorry to say. You'd need to returnfalse
from it and then callclose()
if the user wants to confirm the close (which will triggerpreClose
again, so you'd need a flag to indicate that it should complete!).Allan