MDL-56577 core_form: Let other option attrs to be set in select elements
This commit is contained in:
+12
-1
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
{{/error}}
|
||||
{{element.attributes}} >
|
||||
{{#element.options}}
|
||||
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{text}}</option>
|
||||
<option value="{{value}}" {{#selected}}selected{{/selected}} {{#disabled}}disabled{{/disabled}} {{{optionattributes}}}>{{text}}</option>
|
||||
{{/element.options}}
|
||||
</select>
|
||||
{{/element.frozen}}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
{{/error}}
|
||||
{{element.attributes}} >
|
||||
{{#element.options}}
|
||||
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{text}}</option>
|
||||
<option value="{{value}}" {{#selected}}selected{{/selected}} {{#disabled}}disabled{{/disabled}} {{{optionattributes}}}>{{text}}</option>
|
||||
{{/element.options}}
|
||||
</select>
|
||||
{{/element.frozen}}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<optgroup label="{{text}}">
|
||||
{{/text}}
|
||||
{{#options}}
|
||||
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{{text}}}</option>
|
||||
<option value="{{value}}" {{#selected}}selected{{/selected}} {{#disabled}}disabled{{/disabled}} {{{optionattributes}}}>{{{text}}}</option>
|
||||
{{/options}}
|
||||
{{#text}}
|
||||
</optgroup>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<optgroup label="{{text}}">
|
||||
{{/text}}
|
||||
{{#options}}
|
||||
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{{text}}}</option>
|
||||
<option value="{{value}}" {{#selected}}selected{{/selected}} {{#disabled}}disabled{{/disabled}} {{{optionattributes}}}>{{{text}}}</option>
|
||||
{{/options}}
|
||||
{{/element.optiongroups}}
|
||||
{{#text}}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
{{/error}}
|
||||
{{element.attributes}} >
|
||||
{{#element.options}}
|
||||
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{text}}</option>
|
||||
<option value="{{value}}" {{#selected}}selected{{/selected}} {{#disabled}}disabled{{/disabled}} {{{optionattributes}}}>{{text}}</option>
|
||||
{{/element.options}}
|
||||
</select>
|
||||
{{/element.frozen}}
|
||||
|
||||
Reference in New Issue
Block a user