element-select.mustache 4.18 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{{!
    This file is part of Moodle - http://moodle.org/

    Moodle is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Moodle is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
}}
{{!
    @template core_form/element-select

    Simple select form element template.

    Context variables required for this template:
    * id - Element id,
    * name - Element name,
    * label -  Element label,
    * multiple - multi select?,
    * checked - checked?,
    * error - Is there an error associated with this element?,
    * size - Element size,
    * value - Element value,
    * helpbutton - Helpbutton,
    * hiddenlabel - Element hidden flag,
    * frozen - Element frozen flag,
    * hardfrozen - Element hard fronzen flag,
    * extraclasses - Extra classes assocaited,
    * type - Element type,
    * attributes - Element attributes,
    * options - [
        {
            text - Option text,
            value - Option value,
            selected - Selected?,
            disabled - Disabled?,
            optionattributes - Option attributes
        }
    ]

    Example context (json):
    {
        "element": {
            "id": "id_maildisplay",
            "name": "maildisplay",
            "label": null,
            "multiple": null,
            "checked": null,
            "error": null,
            "size": null,
            "value": null,
            "helpbutton": "",
            "hiddenlabel": false,
            "frozen": false,
            "hardfrozen": false,
            "extraclasses": null,
            "type": "select",
            "attributes": "",
            "options": [
                {
                    "text": "Hide my email address from everyone",
                    "value": 0,
                    "selected": false,
                    "disabled": false,
                    "optionattributes": ""
                },
                {
                    "text": "Allow everyone to see my email address",
                    "value": 1,
                    "selected": true,
                    "disabled": false,
                    "optionattributes": ""
                },
                {
                    "text": "Allow only other course members to see my email address",
                    "value": 2,
                    "selected": false,
                    "disabled": false,
                    "optionattributes": ""
                }
            ]
        }
    }
}}
92
93
{{< core_form/element-template }}
    {{$element}}
94
        {{^element.frozen}}
95
96
97
98
        <select class="{{^element.multiple}}custom-select{{/element.multiple}}
                       {{#element.multiple}}form-control{{/element.multiple}}
                       {{#error}}form-control-danger{{/error}}"
            name="{{element.name}}"
99
            id="{{element.id}}"
100
            {{#element.multiple}}multiple size="{{element.size}}"{{/element.multiple}}
101
102
103
            {{#error}}
                autofocus aria-describedby="id_error_{{element.name}}"
            {{/error}}
104
            {{{element.attributes}}} >
105
            {{#element.options}}
106
            <option value="{{value}}" {{#selected}}selected{{/selected}} {{#disabled}}disabled{{/disabled}} {{{optionattributes}}}>{{text}}</option>
107
108
            {{/element.options}}
        </select>
109
110
111
112
        {{/element.frozen}}
        {{#element.frozen}}
            {{#element.options}}
                {{#selected}}
113
                    {{{text}}}
114
115
116
                    {{^element.hardfrozen}}
                        <input type="hidden" name="{{element.name}}" value="{{value}}" id="{{element.id}}">
                    {{/element.hardfrozen}}
117
118
119
                {{/selected}}
            {{/element.options}}
        {{/element.frozen}}
120
    {{/element}}
121
{{/ core_form/element-template }}