From: Romain Thouvenin Date: Tue, 9 Mar 2021 15:07:02 +0000 (+0100) Subject: Replace the option groups HTML for select2 in one chunk to improve performance when... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=704a585bc64ec8c447cbe484e051498207f238f9;p=civicrm-core.git Replace the option groups HTML for select2 in one chunk to improve performance when many campaigns --- 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