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
This commit is contained in:
nathan 2023-07-25 09:38:11 -06:00
parent 06af22a46c
commit 2a5d0062dd

View File

@ -591,19 +591,34 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(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 = <SelectOption>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 = <SelectOption>result.find(o => o.value == newValueElement);
if(option)
{
this._selected_remote.push(option);
}
});
}
protected fix_bad_value()
{
if(!this.allowFreeEntries && !this.searchEnabled)