diff --git a/lib/form/select.php b/lib/form/select.php index d0a03dc7907..e0f8cf93150 100644 --- a/lib/form/select.php +++ b/lib/form/select.php @@ -200,6 +200,8 @@ class MoodleQuickForm_select extends HTML_QuickForm_select implements templatabl $context = $this->export_for_template_base($output); $options = []; + // Standard option attributes. + $standardoptionattributes = ['text', 'value', 'selected', 'disabled']; foreach ($this->_options as $option) { if (is_array($this->_values) && in_array( (string) $option['attr']['value'], $this->_values)) { $this->_updateAttrArray($option['attr'], ['selected' => 'selected']); @@ -207,8 +209,17 @@ class MoodleQuickForm_select extends HTML_QuickForm_select implements templatabl $o = [ 'text' => $option['text'], 'value' => $option['attr']['value'], - 'selected' => !empty($option['attr']['selected']) + 'selected' => !empty($option['attr']['selected']), + 'disabled' => !empty($option['attr']['disabled']), ]; + // Set other attributes. + $otheroptionattributes = []; + foreach ($option['attr'] as $attr => $value) { + if (!in_array($attr, $standardoptionattributes) && $attr != 'class' && !is_object($value)) { + $otheroptionattributes[] = $attr . '="' . s($value) . '"'; + } + } + $o['optionattributes'] = implode(' ', $otheroptionattributes); $options[] = $o; } $context['options'] = $options; diff --git a/lib/form/selectgroups.php b/lib/form/selectgroups.php index ab547cf75ee..9ed4d050547 100644 --- a/lib/form/selectgroups.php +++ b/lib/form/selectgroups.php @@ -522,6 +522,8 @@ class MoodleQuickForm_selectgroups extends HTML_QuickForm_element implements tem ]; } + // Standard option attributes. + $standardoptionattributes = ['text', 'value', 'selected', 'disabled']; foreach ($this->_optGroups as $group) { $options = []; @@ -533,6 +535,15 @@ class MoodleQuickForm_selectgroups extends HTML_QuickForm_element implements tem $o['selected'] = false; } $o['text'] = $option['text']; + $o['disabled'] = !empty($option['attr']['disabled']); + // Set other attributes. + $otheroptionattributes = []; + foreach ($option['attr'] as $attr => $value) { + if (!in_array($attr, $standardoptionattributes) && $attr != 'class' && !is_object($value)) { + $otheroptionattributes[] = $attr . '="' . s($value) . '"'; + } + } + $o['optionattributes'] = implode(' ', $otheroptionattributes); $options[] = $o; } diff --git a/lib/form/selectwithlink.php b/lib/form/selectwithlink.php index 1643e6f383e..fc4a91598eb 100644 --- a/lib/form/selectwithlink.php +++ b/lib/form/selectwithlink.php @@ -231,6 +231,8 @@ class MoodleQuickForm_selectwithlink extends HTML_QuickForm_select implements te $context = $this->export_for_template_base($output); $options = []; + // Standard option attributes. + $standardoptionattributes = ['text', 'value', 'selected', 'disabled']; foreach ($this->_options as $option) { if (is_array($this->_values) && in_array( (string) $option['attr']['value'], $this->_values)) { $this->_updateAttrArray($option['attr'], ['selected' => 'selected']); @@ -238,8 +240,17 @@ class MoodleQuickForm_selectwithlink extends HTML_QuickForm_select implements te $o = [ 'text' => $option['text'], 'value' => $option['attr']['value'], - 'selected' => !empty($option['attr']['selected']) + 'selected' => !empty($option['attr']['selected']), + 'disabled' => !empty($option['attr']['disabled']), ]; + // Set other attributes. + $otheroptionattributes = []; + foreach ($option['attr'] as $attr => $value) { + if (!in_array($attr, $standardoptionattributes) && $attr != 'class' && !is_object($value)) { + $otheroptionattributes[] = $attr . '="' . s($value) . '"'; + } + } + $o['optionattributes'] = implode(' ', $otheroptionattributes); $options[] = $o; } $context['options'] = $options; diff --git a/theme/boost/templates/core_form/element-select-inline.mustache b/theme/boost/templates/core_form/element-select-inline.mustache index 155f101b769..6362a7a3963 100644 --- a/theme/boost/templates/core_form/element-select-inline.mustache +++ b/theme/boost/templates/core_form/element-select-inline.mustache @@ -9,7 +9,7 @@ {{/error}} {{element.attributes}} > {{#element.options}} - + {{/element.options}} {{/element.frozen}} diff --git a/theme/boost/templates/core_form/element-select.mustache b/theme/boost/templates/core_form/element-select.mustache index 4ac65602434..6947361af19 100644 --- a/theme/boost/templates/core_form/element-select.mustache +++ b/theme/boost/templates/core_form/element-select.mustache @@ -9,7 +9,7 @@ {{/error}} {{element.attributes}} > {{#element.options}} - + {{/element.options}} {{/element.frozen}} diff --git a/theme/boost/templates/core_form/element-selectgroups-inline.mustache b/theme/boost/templates/core_form/element-selectgroups-inline.mustache index 3889a8714d7..72e767a3932 100644 --- a/theme/boost/templates/core_form/element-selectgroups-inline.mustache +++ b/theme/boost/templates/core_form/element-selectgroups-inline.mustache @@ -13,7 +13,7 @@ {{/text}} {{#options}} - + {{/options}} {{#text}} diff --git a/theme/boost/templates/core_form/element-selectgroups.mustache b/theme/boost/templates/core_form/element-selectgroups.mustache index 99b93e2c497..88fef747861 100644 --- a/theme/boost/templates/core_form/element-selectgroups.mustache +++ b/theme/boost/templates/core_form/element-selectgroups.mustache @@ -13,7 +13,7 @@ {{/text}} {{#options}} - + {{/options}} {{/element.optiongroups}} {{#text}} diff --git a/theme/boost/templates/core_form/element-selectwithlink.mustache b/theme/boost/templates/core_form/element-selectwithlink.mustache index f561e5ade1d..66cbe9c099f 100644 --- a/theme/boost/templates/core_form/element-selectwithlink.mustache +++ b/theme/boost/templates/core_form/element-selectwithlink.mustache @@ -9,7 +9,7 @@ {{/error}} {{element.attributes}} > {{#element.options}} - + {{/element.options}} {{/element.frozen}}