diff --git a/libraries/src/Form/FormField.php b/libraries/src/Form/FormField.php index 5b6c0c84c3965..29bbad8ec2cd7 100644 --- a/libraries/src/Form/FormField.php +++ b/libraries/src/Form/FormField.php @@ -1019,7 +1019,20 @@ public function renderField($options = []) ? ((string) $this->form->getXml()->config->inlinehelp['button'] == 'show' ?: false) : false; - if ($this->showon) { + // Check if the field has showon in nested option + $hasOptionShowOn = false; + + if (!empty((array) $this->element->xpath('option'))) { + foreach ($this->element->xpath('option') as $option) { + if ((string) $option['showon']) { + $hasOptionShowOn = true; + + break; + } + } + } + + if ($this->showon || $hasOptionShowOn) { $options['rel'] = ' data-showon=\'' . json_encode(FormHelper::parseShowOnConditions($this->showon, $this->formControl, $this->group)) . '\''; $options['showonEnabled'] = true; @@ -1252,17 +1265,12 @@ public function postProcess($value, $group = null, Registry $input = null) */ protected function getLayoutData() { - // Label preprocess - $label = !empty($this->element['label']) ? (string) $this->element['label'] : null; - $label = $label && $this->translateLabel ? Text::_($label) : $label; - - // Description preprocess + $label = !empty($this->element['label']) ? (string) $this->element['label'] : null; + $label = $label && $this->translateLabel ? Text::_($label) : $label; $description = !empty($this->description) ? $this->description : null; $description = !empty($description) && $this->translateDescription ? Text::_($description) : $description; - - $alt = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname); - - return [ + $alt = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname); + $options = [ 'autocomplete' => $this->autocomplete, 'autofocus' => $this->autofocus, 'class' => $this->class, @@ -1292,6 +1300,8 @@ protected function getLayoutData() 'dataAttributes' => $this->dataAttributes, 'parentclass' => $this->parentclass, ]; + + return $options; } /**