Skip to content

Commit 59b88e8

Browse files
authored
multiple select (#342)
1 parent 4fc04d9 commit 59b88e8

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

docs/3.0/fields/select.md

+38-14
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ The `Select` field renders a `select` field.
1111
field :type, as: :select, options: { 'Large container': :large, 'Medium container': :medium, 'Tiny container': :tiny }, display_with_value: true, placeholder: 'Choose the type of the container.'
1212
```
1313

14-
## Options
15-
1614
<Option name="`options`">
1715

1816
A `Hash` representing the options that should be displayed in the select. The keys represent the labels, and the values represent the value stored in the database.
@@ -25,7 +23,26 @@ The options get cast as `ActiveSupport::HashWithIndifferentAccess` objects if th
2523

2624
#### Possible values
2725

28-
`{ 'Large container': :large, 'Medium container': :medium, 'Tiny container': :tiny }` or any other `Hash`.
26+
- `{ 'Large container': :large, 'Medium container': :medium, 'Tiny container': :tiny }` or any other `Hash`.
27+
- A lambda function that returns a `Hash` (computed options)
28+
29+
### Computed options
30+
31+
You may want to compute the values on the fly for your `Select` field. You can use a lambda for that where you have access to the `record`, `resource`, `view`, and `field` properties where you can pull data off.
32+
33+
```ruby{5-7}
34+
# app/avo/resources/project.rb
35+
class Avo::Resources::Project < Avo::BaseResource
36+
field :type,
37+
as: :select,
38+
options: -> do
39+
record.get_types_from_the_database.map { |type| [type.name, type.id] }
40+
end,
41+
placeholder: 'Choose the type of the container.'
42+
end
43+
```
44+
45+
The output value must be a supported [`options_for_select`](https://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select) value.
2946
</Option>
3047

3148
<Option name="`enum`">
@@ -75,8 +92,6 @@ end
7592

7693
<Option name="`include_blank`">
7794

78-
## Include blank
79-
8095
The `Select` field also has the `include_blank` option. That can have three values.
8196

8297
If it's set to `false` (default), it will not show any blank option but only the options you configured.
@@ -103,20 +118,29 @@ end
103118
`nil`, `true`, `false`, or a string to be used as the first option.
104119
</Option>
105120

106-
## Computed options
121+
<Option name="`multiple`">
107122

108-
You may want to compute the values on the fly for your `Select` field. You can use a lambda for that where you have access to the `record`, `resource`, `view`, and `field` properties where you can pull data off.
123+
<VersionReq version="3.17.3" />
109124

110-
```ruby{5-7}
125+
If it's set to `false` (default), it will only allow selecting a single option from the list.
126+
127+
If it's set to `true`, it will enable multiple selections, allowing users to choose more than one option at a time.
128+
129+
```ruby{5}
111130
# app/avo/resources/project.rb
112131
class Avo::Resources::Project < Avo::BaseResource
113-
field :type,
132+
field :categories,
114133
as: :select,
115-
options: -> do
116-
record.get_types_from_the_database.map { |type| [type.name, type.id] }
117-
end,
118-
placeholder: 'Choose the type of the container.'
134+
multiple: true
119135
end
120136
```
121137

122-
The output value must be a supported [`options_for_select`](https://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select) value.
138+
#### Default
139+
140+
`false`
141+
142+
#### Possible values
143+
144+
`true` or `false`
145+
146+
</Option>

0 commit comments

Comments
 (0)