Timeout needed for "Ctrl + Return" to submit and reopen form
Timeout needed for "Ctrl + Return" to submit and reopen form

Referencing this previous post: https://datatables.net/forums/discussion/comment/140733/
Summary:
* The post discusses the form-options
onReturn
for an Editor
* The function detects if Ctrl is also pressed when submitting the form with Return
* The goal is to submit and immediately reopen the form for a new entry using "Ctrl + Return"
Here's the way I had been doing it, which worked for several years (or probably more accurately, several subsequent versions of Editor):
formOptions: {
main: {
onReturn: function (editor, ev) {
if (ev.ctrlKey) {
editor.submit(() => {
editor.create();
});
} else {
editor.submit();
}
}
}
},
However it had stopped working a while ago and I never troubleshot the issue until today.
I've had to add a small timeout to get it to work again:
formOptions: {
main: {
onReturn: function (editor, ev) {
if (ev.ctrlKey) {
editor.submit(function() {
// Timeout added
setTimeout(function () {
editor.create()
}, 200)
})
} else {
editor.submit()
}
}
}
}
Not sure if that's the best way, but wanted to pass along the update in case anyone else needed it and open it up to discussion if there's a better way to do it.
This question has an accepted answers - jump to answer
Answers
Many thanks for the update. Great to hear you have a workaround.
Allan