From c8517376b1f13e594e9796b22009f217b072b98c Mon Sep 17 00:00:00 2001 From: Matt Elkins <42969457+mattelkins-bluefrontier@users.noreply.github.com> Date: Sat, 10 Aug 2024 10:41:35 +0100 Subject: [PATCH] [5.1] Fix JavaScript error caused by using "switcher" layout for radio buttons in subforms (#43804) --- .../js/fields/joomla-field-subform.w-c.es6.js | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/build/media_source/system/js/fields/joomla-field-subform.w-c.es6.js b/build/media_source/system/js/fields/joomla-field-subform.w-c.es6.js index 305b0d7c7165f..41d7defebcc8a 100644 --- a/build/media_source/system/js/fields/joomla-field-subform.w-c.es6.js +++ b/build/media_source/system/js/fields/joomla-field-subform.w-c.es6.js @@ -287,9 +287,12 @@ class JoomlaFieldSubform extends HTMLElement { // Set the id for fieldset and group label if (!countMulti) { // Look for
or - let fieldset = $el.closest('.checkboxes'); + let fieldset = $el.closest('.checkboxes, fieldset'); // eslint-disable-next-line no-nested-ternary - fieldset = fieldset.nodeName === 'FIELDSET' ? fieldset : (fieldset.parentElement.nodeName === 'FIELDSET' ? fieldset.parentElement : false); + if (fieldset) { + // eslint-disable-next-line no-nested-ternary + fieldset = fieldset.nodeName === 'FIELDSET' ? fieldset : (fieldset.parentElement.nodeName === 'FIELDSET' ? fieldset.parentElement : false); + } if (fieldset) { const oldSetId = fieldset.id; @@ -313,10 +316,17 @@ class JoomlaFieldSubform extends HTMLElement { // Set the id for fieldset and group label if (!countMulti) { - // Look for or - let fieldset = $el.closest('.radio'); - // eslint-disable-next-line no-nested-ternary - fieldset = fieldset.nodeName === 'FIELDSET' ? fieldset : (fieldset.parentElement.nodeName === 'FIELDSET' ? fieldset.parentElement : false); + /** + * Look for one of: + * - + * - + * - + */ + let fieldset = $el.closest('.radio, .switcher, fieldset'); + if (fieldset) { + // eslint-disable-next-line no-nested-ternary + fieldset = fieldset.nodeName === 'FIELDSET' ? fieldset : (fieldset.parentElement.nodeName === 'FIELDSET' ? fieldset.parentElement : false); + } if (fieldset) { const oldSetId = fieldset.id;