Resolve(false) in promise after initEdit does not stop editor from opening

Resolve(false) in promise after initEdit does not stop editor from opening

kharteveldkharteveld Posts: 4Questions: 2Answers: 0

Hi,

In some cases I want to show users a modal to ask if they are sure they want to edit a row. Here is the code I use:

editor.on('initEdit', function (e, node, data, items, type) {
let checks = Array.from(data['checks']);
if (checks.length) {
$('#infoModalChecks').modal('show');
return new Promise((resolve, reject) => {
$('#infoModalButtonChecks').off('click').on('click', function() {
$('#infoModalChecks').modal('hide');
resolve(true);
})
$('#infoModalCloseButtonChecks, #infoModalCloseXChecks').off('click').on('click', function() {
resolve(false);
})
});
}
});

If the user presses the close button in the modal, the editor shouldn't open. But resolve(false) does not stop the editor from opening and reject causes an error in DataTables. Am I doing something wrong? Any help will be greatly appreciated.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,352Questions: 1Answers: 10,443 Site admin
    Answer ✓

    Hi,

    The initEdit event is not cancellable I'm afraid. The opening is delayed until the Promise is resolved but at the moment the init* events cannot be cancelled. The pre* events can be - so preOpen could be used to stop the display.

    Allan

  • kharteveldkharteveld Posts: 4Questions: 2Answers: 0

    Thanks for the quick reply, Allan!

Sign In or Register to comment.