2 This file is part of Moodle - http://moodle.org/
4 Moodle is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 Moodle is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 @template core/select_menu
20 Template for select_menu output component.
22 Context variables required for this template:
23 * name - name of the form element
24 * value - value of the form element
25 * baseid - id of the dropdown element and to be used to generate id for other elements used internally
26 * label - Element label
27 * labelattributes - Label attributes.
28 * selectedoption - Text of the selected option
29 * options - Array of options for the select with value, name, selected, isgroup and id properites.
31 Example context (json):
35 "baseid": "select-menu56789",
36 "label": "Select one option",
40 "value": "font-weight-bold"
43 "selectedoption": "Second option",
46 "name": "First option",
48 "id": "select-menu-option1",
52 "name": "Second option",
54 "id": "select-menu-option2",
60 "name": "First group",
61 "id": "select-menu-group1",
64 "name": "Third option",
66 "id": "select-menu-option3",
70 "name": "Fourth option",
72 "id": "select-menu-option4",
79 "name": "Fifth option",
81 "id": "select-menu-option5",
87 <div class="dropdown select-menu" id="{{baseid}}">
89 <label id="{{baseid}}-label"{{#labelattributes}} {{name}}="{{value}}"{{/labelattributes}}>{{label}}</label>
92 class="btn dropdown-toggle"
94 data-toggle="dropdown"
95 {{#label}}aria-labelledby="{{baseid}}-label"{{/label}}
96 aria-haspopup="listbox"
98 aria-controls="{{baseid}}-listbox"
99 data-input-element="{{baseid}}-input"
104 <ul class="dropdown-menu" role="listbox" id="{{baseid}}-listbox" {{#label}}aria-labelledby="{{baseid}}-label"{{/label}}>
108 <ul role="group" aria-labelledby="{{id}}">
109 <li role="presentation" id="{{id}}">{{name}}</li>
111 <li class="dropdown-item" role="option" id="{{id}}" data-value="{{value}}" {{#selected}}aria-selected="true"{{/selected}}>
119 <li class="dropdown-item" role="option" id="{{id}}" data-value="{{value}}" {{#selected}}aria-selected="true"{{/selected}}>
125 <input type="hidden" name="{{name}}" value="{{value}}" id="{{baseid}}-input">
128 var label = document.getElementById('{{baseid}}-label');
130 label.addEventListener('click', function() {
131 this.parentElement.querySelector('.dropdown-toggle').focus();