diff --git a/api/js/etemplate/Et2Select/SearchMixin.ts b/api/js/etemplate/Et2Select/SearchMixin.ts index 7a04fd0511..5d16153002 100644 --- a/api/js/etemplate/Et2Select/SearchMixin.ts +++ b/api/js/etemplate/Et2Select/SearchMixin.ts @@ -1133,11 +1133,11 @@ export const Et2WithSearchMixin = >(superclass * @param {string} search * @protected */ - protected remoteSearch(search : string, options : object) + protected remoteSearch(search : string, options : object) : Promise { if(!this.searchUrl) { - return Promise.resolve(); + return Promise.resolve([]); } // Check our URL: JSON file or URL? @@ -1149,10 +1149,8 @@ export const Et2WithSearchMixin = >(superclass else { // Fire off the query to the server - let promise = this.remoteQuery(search, options); + return this.remoteQuery(search, options); } - - return promise; } /** @@ -1162,7 +1160,7 @@ export const Et2WithSearchMixin = >(superclass * @param {object} options * @protected */ - protected jsonQuery(search : string, options : object) + protected jsonQuery(search : string, options : object) : Promise { // Get the file const controller = new AbortController(); @@ -1204,7 +1202,7 @@ export const Et2WithSearchMixin = >(superclass * @returns {any} * @protected */ - protected remoteQuery(search : string, options : object) + protected remoteQuery(search : string, options : object) : Promise { // Include a limit, even if options don't, to avoid massive lists breaking the UI let sendOptions = { @@ -1212,29 +1210,30 @@ export const Et2WithSearchMixin = >(superclass ...options } return this.egw().request(this.egw().link(this.egw().ajaxUrl(this.egw().decodePath(this.searchUrl)), - {query: search, ...sendOptions}), [search, sendOptions]).then((result) => + {query: search, ...sendOptions}), [search, sendOptions]).then((results) => { - this.processRemoteResults(result); - return result; + // If results have a total included, pull it out. + // It will cause errors if left in the results + let total = null; + if(typeof results.total !== "undefined") + { + total = results.total; + delete results.total; + } + let entries = cleanSelectOptions(results); + this.processRemoteResults(entries, total); + return entries; }); } /** * Add in remote results * @param results + * @param totalResults If there are more results than were returned, total number of matches * @protected */ - protected processRemoteResults(results) + protected processRemoteResults(entries, totalResults = 0) { - // If results have a total included, pull it out. - // It will cause errors if left in the results - let total = null; - if(typeof results.total !== "undefined") - { - total = results.total; - delete results.total; - } - let entries = cleanSelectOptions(results); let resultCount = entries.length; if(entries.length == 0) @@ -1283,12 +1282,12 @@ export const Et2WithSearchMixin = >(superclass }) .then(() => { - if(total && total > resultCount) + if(totalResults && totalResults > resultCount) { // More results available that were not sent let count = document.createElement("span") count.classList.add("remote"); - count.textContent = this.egw().lang("%1 more...", total - resultCount); + count.textContent = this.egw().lang("%1 more...", totalResults - resultCount); target.appendChild(count); } });