Clone tag dialog on escape key, but not close modal

This commit is contained in:
Matias De lellis
2019-11-12 22:01:32 -03:00
parent 4663d18760
commit 1b6b9cd706

View File

@@ -61,6 +61,18 @@ const QnDialogs = {
input.val(selectedTags.map(function (value) { return value.id; })); input.val(selectedTags.map(function (value) { return value.id; }));
input.trigger("change"); 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(): // wrap callback in _.once():
// only call callback once and not twice (button handler and close // 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 // event) but call it for the close event, if ESC or the x is hit
@@ -91,17 +103,19 @@ const QnDialogs = {
]; ];
$(dialogId).ocdialog({ $(dialogId).ocdialog({
closeOnEscape: true, closeOnEscape: false,
modal: true, modal: true,
buttons: buttonlist, buttons: buttonlist,
close: function () { close: function () {
input.select2("close");
// callback is already fired if Yes/No is clicked directly // callback is already fired if Yes/No is clicked directly
if (callback !== undefined) { if (callback !== undefined) {
callback(false, input.val()); callback(false, input.val());
} }
} }
}); });
input.focus();
$('.select2-input').focus();
}); });
}, },
_getMessageTemplate: function () { _getMessageTemplate: function () {