From 5b9ee2db39721f8bbea0a4b67e248e6f5c7afb39 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 1 Dec 2023 09:32:47 -0700 Subject: [PATCH] Et2Select: Fix missing option detection when options have optgroups Was unable to find option in Timezones, resulting in an infinite loop --- api/js/etemplate/Et2Select/SearchMixin.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/api/js/etemplate/Et2Select/SearchMixin.ts b/api/js/etemplate/Et2Select/SearchMixin.ts index 3b266bff7b..4db9d90bba 100644 --- a/api/js/etemplate/Et2Select/SearchMixin.ts +++ b/api/js/etemplate/Et2Select/SearchMixin.ts @@ -377,10 +377,21 @@ export const Et2WithSearchMixin = dedupeMixin( } if(this.searchEnabled) { + let search = function(options, value) + { + return options.some((option) => + { + if(Array.isArray(option.value)) + { + return search(option.value, value); + } + return option.value == value; + }); + }; // Check to see if value is for an option we do not have for(const newValueElement of this.getValueAsArray()) { - if(this.select_options.some(o => o.value == newValueElement)) + if(search(this.select_options, newValueElement)) { continue; } @@ -1347,7 +1358,7 @@ export const Et2WithSearchMixin = dedupeMixin( * @returns {boolean} * @protected */ - protected searchMatch(search, option : SelectOption) : boolean + protected searchMatch(search : string, option : SelectOption) : boolean { if(!option || !option.value) {