From 2c3e4e5f32ef628e84f04068cab4a5fb48ac939a Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio.bekerle@tugraz.at> Date: Tue, 8 Oct 2019 15:03:54 +0200 Subject: [PATCH] Prevent closing of search dropdown on loosing of focus while searching --- .../person-select/src/vpu-person-select.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/person-select/src/vpu-person-select.js b/packages/person-select/src/vpu-person-select.js index 94a465d9..c0c01cf9 100644 --- a/packages/person-select/src/vpu-person-select.js +++ b/packages/person-select/src/vpu-person-select.js @@ -28,6 +28,7 @@ class PersonSelect extends VPULitElementJQuery { this.selectId = 'person-select-' + commonUtils.makeId(24); this.value = ''; this.ignoreValueUpdate = false; + this.isSearching = false; } static get properties() { @@ -88,11 +89,12 @@ class PersonSelect extends VPULitElementJQuery { placeholder: i18n.t('person-select.placeholder'), dropdownParent: this.$('#person-select-dropdown'), ajax: { - delay: 250, + delay: 500, url: apiUrl, contentType: "application/ld+json", beforeSend: function (jqXHR) { jqXHR.setRequestHeader('Authorization', 'Bearer ' + window.VPUAuthToken); + that.isSearching = true; }, data: function (params) { return { @@ -113,7 +115,10 @@ class PersonSelect extends VPULitElementJQuery { results: results }; }, - error: errorUtils.handleXhrError + error: errorUtils.handleXhrError, + complete: (jqXHR, textStatus) => { + that.isSearching = false; + } } }).on("select2:select", function (e) { // set custom element attributes @@ -135,8 +140,17 @@ class PersonSelect extends VPULitElementJQuery { bubbles: true })); } + }).on("select2:closing", (e) => { + if (that.isSearching) { + e.preventDefault(); + } }); + // TODO: doesn't work here + // this.$('.select2-selection__arrow').click(() => { + // console.log("click"); + // }); + // preset a person if (!ignorePreset && this.value !== '') { const apiUrl = this.entryPointUrl + this.value; -- GitLab