From 2a5d0062dd89b6a7417d814e4b7a52421cbd2d92 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 25 Jul 2023 09:38:11 -0600 Subject: [PATCH] Api: SearchMixin improvements to work with Et2LinkSearch more efficiently Moving handling of missing options to overridable method so Et2LinkSearch can use its more efficient method --- api/js/etemplate/Et2Select/SearchMixin.ts | 33 ++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/api/js/etemplate/Et2Select/SearchMixin.ts b/api/js/etemplate/Et2Select/SearchMixin.ts index e2e1b6dd4c..8eb372ca5e 100644 --- a/api/js/etemplate/Et2Select/SearchMixin.ts +++ b/api/js/etemplate/Et2Select/SearchMixin.ts @@ -591,19 +591,34 @@ export const Et2WithSearchMixin = >(superclass continue; } - // Given a value we need to search for - this will add in all matches, including the one needed - this.remoteSearch(newValueElement, this.searchOptions).then((result : SelectOption[]) => - { - const option = result.find(o => o.value == newValueElement); - if(option) - { - this._selected_remote.push(option); - } - }); + this._missingOption(newValueElement); } } } + /** + * Some [part of a] value is missing from the available options, but should be there, so find and add it. + * + * This is used when not all options are sent to the client (search, link list). Ideally we want to send + * the options for the current value, but sometimes this is not the best option so here we search or create + * the option as needed. These are not free entries, but need to match some list somewhere. + * + * @param {string} newValueElement + * @protected + */ + protected _missingOption(newValueElement : string) + { + // Given a value we need to search for - this will add in all matches, including the one needed + this.remoteSearch(newValueElement, this.searchOptions).then((result : SelectOption[]) => + { + const option = result.find(o => o.value == newValueElement); + if(option) + { + this._selected_remote.push(option); + } + }); + } + protected fix_bad_value() { if(!this.allowFreeEntries && !this.searchEnabled)