diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index cac9e619ca6..cb79c92fcc6 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -1020,7 +1020,7 @@ class single_select implements renderable, templatable { var $formid = null; /** - * @var array List of attached actions + * @var help_icon The help icon for this element. */ var $helpicon = null; @@ -1111,7 +1111,19 @@ class single_select implements renderable, templatable { $data->title = $this->tooltip; $data->formid = !empty($this->formid) ? $this->formid : html_writer::random_id('single_select_f'); $data->id = !empty($attributes['id']) ? $attributes['id'] : html_writer::random_id('single_select'); + + // Select element attributes. + // Unset attributes that are already predefined in the template. unset($attributes['id']); + unset($attributes['class']); + unset($attributes['name']); + unset($attributes['title']); + unset($attributes['disabled']); + + // Map the attributes. + $data->attributes = array_map(function($key) use ($attributes) { + return ['name' => $key, 'value' => $attributes[$key]]; + }, array_keys($attributes)); // Form parameters. $params = $this->url->params(); @@ -1185,8 +1197,11 @@ class single_select implements renderable, templatable { // Label attributes. $data->labelattributes = []; + // Unset label attributes that are already in the template. + unset($this->labelattributes['for']); + // Map the label attributes. foreach ($this->labelattributes as $key => $value) { - $data->labelattributes = ['name' => $key, 'value' => $value]; + $data->labelattributes[] = ['name' => $key, 'value' => $value]; } // Help icon. @@ -1260,7 +1275,7 @@ class url_select implements renderable, templatable { var $formid = null; /** - * @var array List of attached actions + * @var help_icon The help icon for this element. */ var $helpicon = null; @@ -1423,6 +1438,7 @@ class url_select implements renderable, templatable { unset($attributes['id']); unset($attributes['name']); unset($attributes['title']); + unset($attributes['disabled']); $data->showbutton = $this->showbutton; @@ -1442,6 +1458,9 @@ class url_select implements renderable, templatable { // Label attributes. $data->labelattributes = []; + // Unset label attributes that are already in the template. + unset($this->labelattributes['for']); + // Map the label attributes. foreach ($this->labelattributes as $key => $value) { $data->labelattributes[] = ['name' => $key, 'value' => $value]; } @@ -1451,8 +1470,8 @@ class url_select implements renderable, templatable { // Finally all the remaining attributes. $data->attributes = []; - foreach ($this->attributes as $key => $value) { - $data->attributes = ['name' => $key, 'value' => $value]; + foreach ($attributes as $key => $value) { + $data->attributes[] = ['name' => $key, 'value' => $value]; } return $data; diff --git a/lib/templates/single_select.mustache b/lib/templates/single_select.mustache index 3994c785477..071d38c2e28 100644 --- a/lib/templates/single_select.mustache +++ b/lib/templates/single_select.mustache @@ -95,7 +95,8 @@ {{#helpicon}} {{>core/help_icon}} {{/helpicon}} - {{#options}} {{#optgroup}} diff --git a/lib/templates/url_select.mustache b/lib/templates/url_select.mustache index 2015076778e..e7d22937657 100644 --- a/lib/templates/url_select.mustache +++ b/lib/templates/url_select.mustache @@ -32,7 +32,9 @@ [ {"name": "Item 3", "isgroup": false, "value": "3"}, {"name": "Item 4", "isgroup": false, "value": "4"} - ]}] + ]}], + "disabled": false, + "title": "Some cool title" } }}
@@ -46,7 +48,8 @@ {{#helpicon}} {{>core/help_icon}} {{/helpicon}} - {{#options}} {{#isgroup}}