From 704a585bc64ec8c447cbe484e051498207f238f9 Mon Sep 17 00:00:00 2001 From: Romain Thouvenin Date: Tue, 9 Mar 2021 16:07:02 +0100 Subject: [PATCH] Replace the option groups HTML for select2 in one chunk to improve performance when many campaigns --- js/Common.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/js/Common.js b/js/Common.js index 8a53067637..e5754fcfe0 100644 --- a/js/Common.js +++ b/js/Common.js @@ -418,11 +418,24 @@ if (!CRM.vars) CRM.vars = {}; formatResult: formatCrmSelect2, formatSelection: formatCrmSelect2 }; + // quickform doesn't support optgroups so here's a hack :( + var optGroups = {}; $('option[value^=crm_optgroup]', this).each(function () { - $(this).nextUntil('option[value^=crm_optgroup]').wrapAll(''); + var groupHtml = ''; + $(this).nextUntil('option[value^=crm_optgroup]').each(function () { + groupHtml += this.outerHTML; + }); + optGroups[$(this).text()] = groupHtml; $(this).remove(); }); + var replacedHtml = ''; + for (var groupLabel in optGroups) { + replacedHtml += '' + optGroups[groupLabel] + ''; + } + if (replacedHtml) { + $el.html(replacedHtml); + } // quickform does not support disabled option, so yet another hack to // add disabled property for option values -- 2.25.1