From e2ed910d787ca28d7d9a53084f3277f5f3d79699 Mon Sep 17 00:00:00 2001 From: Carsten Rose <carsten.rose@math.uzh.ch> Date: Tue, 3 Dec 2019 15:29:35 +0100 Subject: [PATCH] Refs #9691: HTML ID for checkbox elements --- extension/Classes/Core/AbstractBuildForm.php | 25 ++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/extension/Classes/Core/AbstractBuildForm.php b/extension/Classes/Core/AbstractBuildForm.php index 71ab40537..67a7e2f76 100644 --- a/extension/Classes/Core/AbstractBuildForm.php +++ b/extension/Classes/Core/AbstractBuildForm.php @@ -2257,6 +2257,8 @@ abstract class AbstractBuildForm { if ($formElement[FE_MODE] == FE_MODE_READONLY) { $checkboxClass .= ' qfq-disabled'; // necessary for own style checkboxes to display them 'disabled' } + // Used in getFormElementForJson() for dynamic update. + $formElement['_checkboxClass'] = $checkboxClass; $br = ''; @@ -2265,7 +2267,8 @@ abstract class AbstractBuildForm { $jsonValue = false; $attribute = $attributeBase; $htmlFormElementNameUniq = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, $ii, true); - $attribute .= Support::doAttribute('id', $formElement[FE_HTML_ID] . '-' . $ii); + $checkboxId = $this->checkboxRadioOptionId($formElement[FE_HTML_ID], $ii); + $attribute .= Support::doAttribute('id', $checkboxId); $attribute .= Support::doAttribute('name', $htmlFormElementNameUniq); $attribute .= Support::doAttribute(ATTRIBUTE_DATA_REFERENCE, $formElement[FE_DATA_REFERENCE] . '-' . $ii); @@ -2294,7 +2297,8 @@ abstract class AbstractBuildForm { // $htmlElement = Support::wrapTag('<label>', $htmlElement); // } - $htmlElement = Support::wrapTag("<label class='$checkboxClass' $attributeBaseLabel>", $htmlElement, true); + $checkboxLabelId = $this->checkboxRadioOptionId($formElement[FE_HTML_ID], $ii, 'l'); + $htmlElement = Support::wrapTag("<label class='$checkboxClass' $attributeBaseLabel id='$checkboxLabelId'>", $htmlElement, true); // control orientation if ($formElement[FE_MAX_LENGTH] > 1) { @@ -2315,6 +2319,23 @@ abstract class AbstractBuildForm { return $html; } + /** + * Construct HTML ID for checkbox/radio option elements. + * Optional add $type. + * Example: $base='173-21612-1-0', $index='0', $type='l' >> '173-21612-1-0-0-l' + * + * @param $base + * @param $index + * @param string $type - ';' for label + * @return string + */ + private function checkboxRadioOptionId($base, $index, $type = '') { + if ($type != '') { + $type = '-' . $type; + } + return $base . '-' . $index . $type; + + } /** * Submit extra (hidden) values by SIP. * -- GitLab