Skip to content

Commit 7d64919

Browse files
committed
add allow multiple option and documentation
1 parent b520425 commit 7d64919

File tree

2 files changed

+65
-37
lines changed

2 files changed

+65
-37
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ module.exports = {
103103
};
104104
```
105105

106+
#### select field widget option
107+
108+
The select field widget has an option `allowMultiple` to allow multiple select options to be selected. The default value is `false`.
109+
110+
Once set to `true`, it will add two new fields to the select field widget schema:
111+
112+
| Property | Type | Description |
113+
|---|---|---|
114+
| `allowMultiple` | Boolean | Set to `true` to enable multiple values to be selected in the select widget options, default value is `false` |
115+
| `size` | Integer | Number of options in the list that should be visible, default value is `0` |
116+
117+
```javascript
118+
// modules/@apostrophecms/form-select-field/index.js
119+
modules.exports = {
120+
options: {
121+
allowMultiple: false
122+
}
123+
}
124+
```
106125

107126
### Supporting file field uploads safely
108127

modules/@apostrophecms/form-select-field-widget/index.js

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,55 @@ module.exports = {
22
extend: '@apostrophecms/form-base-field-widget',
33
options: {
44
label: 'aposForm:select',
5-
icon: 'form-select-icon'
5+
icon: 'form-select-icon',
6+
allowMultiple: false
67
},
7-
fields: {
8-
add: {
9-
choices: {
10-
label: 'aposForm:selectChoice',
11-
type: 'array',
12-
titleField: 'label',
13-
required: true,
14-
fields: {
15-
add: {
16-
label: {
17-
type: 'string',
18-
required: true,
19-
label: 'aposForm:checkboxChoicesLabel',
20-
help: 'aposForm:checkboxChoicesLabelHelp'
21-
},
22-
value: {
23-
type: 'string',
24-
label: 'aposForm:checkboxChoicesValue',
25-
help: 'aposForm:checkboxChoicesValueHelp'
26-
}
8+
fields(self) {
9+
const optionalFields = self.options.allowMultiple
10+
? {
11+
allowMultiple: {
12+
label: 'aposForm:selectAllowMultiple',
13+
type: 'boolean',
14+
def: false
15+
},
16+
size: {
17+
label: 'aposForm:selectSize',
18+
type: 'integer',
19+
def: 0,
20+
min: 0,
21+
if: {
22+
allowMultiple: true
2723
}
2824
}
29-
},
30-
allowMultiple: {
31-
label: 'aposForm:selectAllowMultiple',
32-
type: 'boolean',
33-
def: false
34-
},
35-
size: {
36-
label: 'aposForm:selectSize',
37-
type: 'integer',
38-
def: 0,
39-
min: 0,
40-
if: {
41-
allowMultiple: true
42-
}
4325
}
44-
}
26+
: {};
27+
28+
return {
29+
add: {
30+
choices: {
31+
label: 'aposForm:selectChoice',
32+
type: 'array',
33+
titleField: 'label',
34+
required: true,
35+
fields: {
36+
add: {
37+
label: {
38+
type: 'string',
39+
required: true,
40+
label: 'aposForm:checkboxChoicesLabel',
41+
help: 'aposForm:checkboxChoicesLabelHelp'
42+
},
43+
value: {
44+
type: 'string',
45+
label: 'aposForm:checkboxChoicesValue',
46+
help: 'aposForm:checkboxChoicesValueHelp'
47+
}
48+
}
49+
}
50+
},
51+
...optionalFields
52+
}
53+
};
4554
},
4655
methods (self) {
4756
return {
@@ -60,7 +69,7 @@ module.exports = {
6069
req,
6170
{
6271
...widget,
63-
allowMultiple: widget.allowMultiple ?? false,
72+
allowMultiple: (self.options.allowMultiple && widget.allowMultiple) ?? false,
6473
size: widget.size ?? 0
6574
},
6675
options,

0 commit comments

Comments
 (0)