This commit is contained in:
Frank Harris 2026-01-27 17:18:17 -06:00
parent 4c24d14bf5
commit 94aeca6c92
4 changed files with 76 additions and 0 deletions

View file

@ -21,12 +21,16 @@
this.searchForm = root.querySelector('.js-sw-search-form');
this.searchInput = root.querySelector('.js-sw-search-input');
this.searchButton = root.querySelector('.js-sw-search-button');
this.requestInput = root.querySelector('.js-sw-request-input');
this.requestSummary = root.querySelector('.js-sw-request-summary');
this.requestSummaryBase = this.requestSummary ? (this.requestSummary.getAttribute('data-base') || '') : '';
this.state = {
selected: this.readInitialSelection(),
};
this.lastResults = [];
this.bindEvents();
this.renderSelected();
this.updateRequestPreview();
}
Picker.prototype.readInitialSelection = function () {
if (!this.selectedInput) {
@ -73,6 +77,11 @@
}
});
}
if (this.searchInput) {
this.searchInput.addEventListener('input', function () {
_this.updateRequestPreview();
});
}
if (this.selectedList) {
this.selectedList.addEventListener('click', function (event) {
var target = event.target;
@ -126,6 +135,7 @@
return;
}
var term = this.searchInput.value.trim();
this.updateRequestPreview();
if (!term) {
this.setStatus(this.lang.query, 'error');
return;
@ -222,6 +232,18 @@
_loop_1(item);
}
};
Picker.prototype.updateRequestPreview = function () {
if (this.requestInput && this.searchInput) {
this.requestInput.value = this.searchInput.value;
}
if (this.requestSummary) {
var encoded = '';
if (this.searchInput && this.searchInput.value.trim() !== '') {
encoded = encodeURIComponent(this.searchInput.value.trim());
}
this.requestSummary.textContent = (this.requestSummaryBase || '') + encoded;
}
};
Picker.prototype.isSelected = function (id) {
return this.state.selected.some(function (item) { return item.id === id; });
};