Merge branch 'MDL-61839-master' of git://github.com/mihailges/moodle
[moodle.git] / lib / templates / url_select.mustache
blob09048960ba9f94edac069f59e96728099e878dda
1 {{!
2     @template core/url_select
4     Example context (json):
5     {
6         "id": "url_select_test",
7         "action": "https://example.com/post",
8         "formid": "url_select_form",
9         "sesskey": "sesskey",
10         "label": "core/url_select",
11         "helpicon": {
12             "title": "Help with something",
13             "text": "Help with something",
14             "url": "http://example.org/help",
15             "linktext": "",
16             "icon":{
17                 "extraclasses": "iconhelp",
18                 "attributes": [
19                     {"name": "src", "value": "../../../pix/help.svg"},
20                     {"name": "alt", "value": "Help icon"}
21                 ]
22             }
23         },
24         "showbutton": "Go",
25         "options": [{
26             "name": "Group 1", "isgroup": true, "options":
27             [
28                 {"name": "Item 1", "isgroup": false, "value": "1"},
29                 {"name": "Item 2", "isgroup": false, "value": "2"}
30             ]},
31             {"name": "Group 2", "isgroup": true, "options":
32             [
33                 {"name": "Item 3", "isgroup": false, "value": "3"},
34                 {"name": "Item 4", "isgroup": false, "value": "4"}
35             ]}]
36     }
38 <div class="{{classes}}">
39     <form method="post" action="{{action}}" class="form-inline" id="{{formid}}">
40         <input type="hidden" name="sesskey" value="{{sesskey}}">
41         {{#label}}
42             <label for="{{id}}"{{#labelattributes}} {{name}}="{{value}}"{{/labelattributes}}>
43                 {{label}}
44             </label>
45         {{/label}}
46         {{#helpicon}}
47             {{>core/help_icon}}
48         {{/helpicon}}
49         <select {{#attributes}}{{name}}="{{value}}" {{/attributes}} id="{{id}}" class="custom-select {{classes}}" name="jump">
50             {{#options}}
51                 {{#isgroup}}
52                     <optgroup label="{{name}}">
53                         {{#options}}
54                             <option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
55                         {{/options}}
56                     </optgroup>
57                 {{/isgroup}}
58                 {{^isgroup}}
59                     <option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
60                 {{/isgroup}}
61             {{/options}}
62         </select>
63         {{#showbutton}}
64             <input type="submit" class="btn btn-secondary" value="{{showbutton}}">
65         {{/showbutton}}
66         {{^showbutton}}
67             <noscript>
68                 <input type="submit" class="btn btn-secondary" value="{{#str}}go, core{{/str}}">
69             </noscript>
70         {{/showbutton}}
71     </form>
72 </div>
73 {{^showbutton}}
74     {{#js}}
75         require(['jquery'], function($) {
76             $('#{{id}}').change(function() {
77                 $('#{{formid}}').submit();
78             });
79         });
80     {{/js}}
81 {{/showbutton}}