diff --git a/packages/person-select/src/vpu-person-select.js b/packages/person-select/src/vpu-person-select.js index 94a465d9cf16a993fc8a6a9e217db21218fbfa88..c0c01cf9c351f0444685dbd0070d7f645a3671aa 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;