aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/issue/template/template.go25
-rw-r--r--modules/issue/template/template_test.go92
-rw-r--r--templates/repo/issue/fields/dropdown.tmpl2
3 files changed, 118 insertions, 1 deletions
diff --git a/modules/issue/template/template.go b/modules/issue/template/template.go
index 3be48b9edc..cf5fcf28e5 100644
--- a/modules/issue/template/template.go
+++ b/modules/issue/template/template.go
@@ -91,6 +91,9 @@ func validateYaml(template *api.IssueTemplate) error {
if err := validateOptions(field, idx); err != nil {
return err
}
+ if err := validateDropdownDefault(position, field.Attributes); err != nil {
+ return err
+ }
case api.IssueFormFieldTypeCheckboxes:
if err := validateStringItem(position, field.Attributes, false, "description"); err != nil {
return err
@@ -249,6 +252,28 @@ func validateBoolItem(position errorPosition, m map[string]any, names ...string)
return nil
}
+func validateDropdownDefault(position errorPosition, attributes map[string]any) error {
+ v, ok := attributes["default"]
+ if !ok {
+ return nil
+ }
+ defaultValue, ok := v.(int)
+ if !ok {
+ return position.Errorf("'default' should be an int")
+ }
+
+ options, ok := attributes["options"].([]any)
+ if !ok {
+ // should not happen
+ return position.Errorf("'options' is required and should be a array")
+ }
+ if defaultValue < 0 || defaultValue >= len(options) {
+ return position.Errorf("the value of 'default' is out of range")
+ }
+
+ return nil
+}
+
type errorPosition string
func (p errorPosition) Errorf(format string, a ...any) error {
diff --git a/modules/issue/template/template_test.go b/modules/issue/template/template_test.go
index e24b962d61..481058754d 100644
--- a/modules/issue/template/template_test.go
+++ b/modules/issue/template/template_test.go
@@ -356,6 +356,96 @@ body:
wantErr: "body[0](checkboxes), option[1]: can not require a hidden checkbox",
},
{
+ name: "dropdown default is not an integer",
+ content: `
+name: "test"
+about: "this is about"
+body:
+ - type: dropdown
+ id: "1"
+ attributes:
+ label: Label of dropdown
+ description: Description of dropdown
+ multiple: true
+ options:
+ - Option 1 of dropdown
+ - Option 2 of dropdown
+ - Option 3 of dropdown
+ default: "def"
+ validations:
+ required: true
+`,
+ wantErr: "body[0](dropdown): 'default' should be an int",
+ },
+ {
+ name: "dropdown default is out of range",
+ content: `
+name: "test"
+about: "this is about"
+body:
+ - type: dropdown
+ id: "1"
+ attributes:
+ label: Label of dropdown
+ description: Description of dropdown
+ multiple: true
+ options:
+ - Option 1 of dropdown
+ - Option 2 of dropdown
+ - Option 3 of dropdown
+ default: 3
+ validations:
+ required: true
+`,
+ wantErr: "body[0](dropdown): the value of 'default' is out of range",
+ },
+ {
+ name: "dropdown without default is valid",
+ content: `
+name: "test"
+about: "this is about"
+body:
+ - type: dropdown
+ id: "1"
+ attributes:
+ label: Label of dropdown
+ description: Description of dropdown
+ multiple: true
+ options:
+ - Option 1 of dropdown
+ - Option 2 of dropdown
+ - Option 3 of dropdown
+ validations:
+ required: true
+`,
+ want: &api.IssueTemplate{
+ Name: "test",
+ About: "this is about",
+ Fields: []*api.IssueFormField{
+ {
+ Type: "dropdown",
+ ID: "1",
+ Attributes: map[string]any{
+ "label": "Label of dropdown",
+ "description": "Description of dropdown",
+ "multiple": true,
+ "options": []any{
+ "Option 1 of dropdown",
+ "Option 2 of dropdown",
+ "Option 3 of dropdown",
+ },
+ },
+ Validations: map[string]any{
+ "required": true,
+ },
+ Visible: []api.IssueFormFieldVisible{api.IssueFormFieldVisibleForm, api.IssueFormFieldVisibleContent},
+ },
+ },
+ FileName: "test.yaml",
+ },
+ wantErr: "",
+ },
+ {
name: "valid",
content: `
name: Name
@@ -399,6 +489,7 @@ body:
- Option 1 of dropdown
- Option 2 of dropdown
- Option 3 of dropdown
+ default: 1
validations:
required: true
- type: checkboxes
@@ -475,6 +566,7 @@ body:
"Option 2 of dropdown",
"Option 3 of dropdown",
},
+ "default": 1,
},
Validations: map[string]any{
"required": true,
diff --git a/templates/repo/issue/fields/dropdown.tmpl b/templates/repo/issue/fields/dropdown.tmpl
index f4fa79738c..26505f58a5 100644
--- a/templates/repo/issue/fields/dropdown.tmpl
+++ b/templates/repo/issue/fields/dropdown.tmpl
@@ -2,7 +2,7 @@
{{template "repo/issue/fields/header" .}}
{{/* FIXME: required validation */}}
<div class="ui fluid selection dropdown {{if .item.Attributes.multiple}}multiple clearable{{end}}">
- <input type="hidden" name="form-field-{{.item.ID}}" value="0">
+ <input type="hidden" name="form-field-{{.item.ID}}" value="{{.item.Attributes.default}}">
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
{{if not .item.Validations.required}}
{{svg "octicon-x" 14 "remove icon"}}
n_same_bucket Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/dropbox.php
blob: 33ca14cab1541fa795b1bcfeda7338e9f75a8977 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277