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/single_select
20 Moodle template for a single select submit form.
22 Context variables required for this template:
23 * name - Element name.
24 * method - get or post.
25 * action - the action url to submit to.
26 * classes - Element classes.
27 * label - Element label.
28 * disabled - true if this element is disabled.
29 * title - Element title.
30 * formid - optional id value for the form.
31 * id - id for the element.
32 * params - array of params with name and value attributes.
33 * options - Array of options for the select with value, name , slected and optgroup properites.
34 * labelattributes - Label attributes.
35 * helpicon - Help icon.
37 Example context (json):
41 "action": "http://localhost/stable_master/mod/scorm/player.php",
42 "classes": "langmenu",
43 "label": "Zombies are coming...",
47 "id": "single_select5833dd4f4b08d108",
63 "value": "eXeMapADrive4823c6301cf72b22b72"
69 "name": "English (en)",
80 "labelattributes": [],
85 <div class="{{classes}} d-inline-block">
86 <form method="{{method}}" action="{{action}}" class="d-flex flex-wrap align-items-center" id="{{formid}}">
88 <input type="hidden" name="{{name}}" value="{{value}}">
91 <label for="{{id}}"{{#labelattributes}} {{name}}="{{value}}"{{/labelattributes}}>
98 <select {{#attributes}}{{name}}="{{value}}" {{/attributes}} id="{{id}}" class="custom-select {{classes}}" name="{{name}}"
99 {{#title}}title="{{.}}"{{/title}} {{#disabled}}disabled{{/disabled}}>
102 <optgroup label="{{name}}">
104 <option value="{{value}}" {{#selected}}selected{{/selected}}>{{{name}}}</option>
109 <option {{ignore}} value="{{value}}" {{#selected}}selected{{/selected}}>{{{name}}}</option>
114 <input type="submit" class="btn btn-secondary ml-1" value="{{#str}}go, core{{/str}}">
119 require(['jquery', 'core/custom_interaction_events'], function($, CustomEvents) {
120 CustomEvents.define('#{{id}}', [CustomEvents.events.accessibleChange]);
121 $('#{{id}}').on(CustomEvents.events.accessibleChange, function() {
122 var ignore = $(this).find(':selected').attr('data-ignore');
123 if (typeof ignore === typeof undefined) {
124 $('#{{formid}}').submit();