| 1 |
efrain |
1 |
{{!
|
|
|
2 |
This file is part of Moodle - http://moodle.org/
|
|
|
3 |
Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
|
5 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
(at your option) any later version.
|
|
|
7 |
Moodle is distributed in the hope that it will be useful,
|
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
10 |
GNU General Public License for more details.
|
|
|
11 |
You should have received a copy of the GNU General Public License
|
|
|
12 |
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
13 |
}}
|
|
|
14 |
{{!
|
|
|
15 |
@template core_form/element-choicedropdown
|
|
|
16 |
Choice dialog form element template.
|
|
|
17 |
Context variables required for this template:
|
|
|
18 |
* id - Element id,
|
|
|
19 |
* nameraw - Raw Element name without '[]'
|
|
|
20 |
* name - Element name,
|
|
|
21 |
* label - Element label,
|
|
|
22 |
* multiple - multi select?,
|
|
|
23 |
* checked - checked?,
|
|
|
24 |
* error - Is there an error associated with this element?,
|
|
|
25 |
* size - Element size,
|
|
|
26 |
* value - Element value,
|
|
|
27 |
* helpbutton - Helpbutton,
|
|
|
28 |
* hiddenlabel - Element hidden flag,
|
|
|
29 |
* frozen - Element frozen flag,
|
|
|
30 |
* hardfrozen - Element hard fronzen flag,
|
|
|
31 |
* extraclasses - Extra classes assocaited,
|
|
|
32 |
* type - Element type,
|
|
|
33 |
* attributes - Element attributes,
|
|
|
34 |
* options - [
|
|
|
35 |
{
|
|
|
36 |
text - Option text,
|
|
|
37 |
value - Option value,
|
|
|
38 |
selected - Selected?,
|
|
|
39 |
disabled - Disabled?,
|
|
|
40 |
optionattributes - Option attributes
|
|
|
41 |
}
|
|
|
42 |
]
|
|
|
43 |
|
|
|
44 |
Example context (json):
|
|
|
45 |
{
|
|
|
46 |
"element": {
|
|
|
47 |
"wrapperid": "fitem_id_choicedropdownfield",
|
|
|
48 |
"iderror": "error_id_choicedropdownfield",
|
|
|
49 |
"id": "id_choicedropdownfield",
|
|
|
50 |
"nameraw": "choicedropdownfield",
|
|
|
51 |
"name": "choicedropdownfield",
|
|
|
52 |
"label": null,
|
|
|
53 |
"multiple": null,
|
|
|
54 |
"checked": null,
|
|
|
55 |
"error": null,
|
|
|
56 |
"size": null,
|
|
|
57 |
"value": null,
|
|
|
58 |
"helpbutton": "",
|
|
|
59 |
"hiddenlabel": false,
|
|
|
60 |
"frozen": false,
|
|
|
61 |
"hardfrozen": false,
|
|
|
62 |
"extraclasses": null,
|
|
|
63 |
"type": "select",
|
|
|
64 |
"attributes": "",
|
|
|
65 |
"fieldicon": "<a class='btn'><i class='icon fa fa-ellipsis-h'></i></a>",
|
|
|
66 |
"options": [
|
|
|
67 |
{
|
|
|
68 |
"rawoptionid": "1",
|
|
|
69 |
"text": "Hidden",
|
|
|
70 |
"value": 0,
|
|
|
71 |
"selected": false,
|
|
|
72 |
"disabled": false,
|
|
|
73 |
"optionattributes": ""
|
|
|
74 |
},
|
|
|
75 |
{
|
|
|
76 |
"rawoptionid": "2",
|
|
|
77 |
"text": "Visible to everyone",
|
|
|
78 |
"value": 1,
|
|
|
79 |
"selected": true,
|
|
|
80 |
"disabled": false,
|
|
|
81 |
"optionattributes": ""
|
|
|
82 |
},
|
|
|
83 |
{
|
|
|
84 |
"rawoptionid": "3",
|
|
|
85 |
"text": "Allow only other course members to see my email address",
|
|
|
86 |
"value": 2,
|
|
|
87 |
"selected": false,
|
|
|
88 |
"disabled": false,
|
|
|
89 |
"optionattributes": ""
|
|
|
90 |
}
|
|
|
91 |
]
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
}}
|
|
|
95 |
{{< core_form/element-template }}
|
|
|
96 |
{{$element}}
|
|
|
97 |
{{^element.frozen}}
|
|
|
98 |
<select
|
| 1441 |
ariadna |
99 |
class="form-select d-none {{#error}}is-invalid{{/error}}"
|
| 1 |
efrain |
100 |
name="{{element.name}}"
|
|
|
101 |
id="{{element.id}}"
|
|
|
102 |
data-region="choice-select"
|
|
|
103 |
{{#element.multiple}}multiple{{/element.multiple}}
|
|
|
104 |
{{#element.size}}size="{{element.size}}"{{/element.size}}
|
|
|
105 |
{{#error}} autofocus aria-describedby="{{element.iderror}}" {{/error}}
|
|
|
106 |
{{{element.attributes}}}
|
|
|
107 |
>
|
|
|
108 |
{{#element.select}}
|
|
|
109 |
{{#options}}
|
|
|
110 |
<option
|
|
|
111 |
value="{{value}}"
|
|
|
112 |
data-optionid="{{element.id}}_{{optionuniqid}}"
|
|
|
113 |
{{#selected}}selected{{/selected}}
|
|
|
114 |
{{#disabled}}disabled{{/disabled}}
|
|
|
115 |
{{{optionattributes}}}
|
|
|
116 |
>
|
|
|
117 |
{{{name}}}
|
|
|
118 |
</option>
|
|
|
119 |
{{/options}}
|
|
|
120 |
{{/element.select}}
|
|
|
121 |
</select>
|
|
|
122 |
{{#element.dropdown}}
|
|
|
123 |
{{< core/local/dropdown/status}}
|
|
|
124 |
{{$ buttonclasses }} btn btn-outline-secondary dropdown-toggle {{/ buttonclasses }}
|
|
|
125 |
{{/ core/local/dropdown/status}}
|
|
|
126 |
{{/element.dropdown}}
|
|
|
127 |
{{/element.frozen}}
|
|
|
128 |
{{#element.frozen}}
|
|
|
129 |
{{#element.options}}
|
|
|
130 |
{{#selected}}
|
|
|
131 |
{{{text}}}
|
|
|
132 |
{{^element.hardfrozen}}
|
|
|
133 |
<input
|
|
|
134 |
type="hidden"
|
|
|
135 |
name="{{element.name}}"
|
|
|
136 |
value="{{value}}"
|
|
|
137 |
id="{{element.id}}"
|
|
|
138 |
>
|
|
|
139 |
{{/element.hardfrozen}}
|
|
|
140 |
{{/selected}}
|
|
|
141 |
{{/element.options}}
|
|
|
142 |
{{/element.frozen}}
|
|
|
143 |
{{/element}}
|
|
|
144 |
{{/ core_form/element-template }}
|
|
|
145 |
{{#js}}
|
|
|
146 |
require(['core_form/choicedropdown'], function(ChioceDropdown) {
|
|
|
147 |
ChioceDropdown.init('{{element.id}}');
|
|
|
148 |
});
|
|
|
149 |
{{/js}}
|