From a2c0234401d6f1ed36182e1a708efff738c4b4a0 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 0a32fb89cc..9a7c978004 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) {