From 1b6b9cd706d0c4497c6f1d9f2d4b5c546d72a4e8 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Tue, 12 Nov 2019 22:01:32 -0300 Subject: [PATCH] Clone tag dialog on escape key, but not close modal --- js/qn-dialogs.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/js/qn-dialogs.js b/js/qn-dialogs.js index 2260cbd..f7da11b 100644 --- a/js/qn-dialogs.js +++ b/js/qn-dialogs.js @@ -61,6 +61,18 @@ const QnDialogs = { input.val(selectedTags.map(function (value) { return value.id; })); input.trigger("change"); + $('.select2-input').on("keyup", function (event) { + if (event.keyCode === 27) { + event.preventDefault(); + event.stopPropagation(); + input.select2('close'); + if (callback !== undefined) { + callback(false, input.select2("data")); + } + $(dialogId).ocdialog('close'); + } + }); + // wrap callback in _.once(): // only call callback once and not twice (button handler and close // event) but call it for the close event, if ESC or the x is hit @@ -91,17 +103,19 @@ const QnDialogs = { ]; $(dialogId).ocdialog({ - closeOnEscape: true, + closeOnEscape: false, modal: true, buttons: buttonlist, close: function () { + input.select2("close"); // callback is already fired if Yes/No is clicked directly if (callback !== undefined) { callback(false, input.val()); } } }); - input.focus(); + + $('.select2-input').focus(); }); }, _getMessageTemplate: function () {