Skip to content

Commit

Permalink
Merge pull request #192 from cloudaper/enable-computed-boolean-group-…
Browse files Browse the repository at this point in the history
…options
  • Loading branch information
adrianthedev authored Apr 12, 2024
2 parents b54507b + c4b5dac commit 6a84f99
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/3.0/fields/boolean_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ field :roles, as: :boolean_group, name: 'User roles', options: { admin: 'Adminis
warning: :warning
}
```

#### Computed options

You may want to compute the values on the fly for your `BooleanGroup` 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.

```ruby{5-7}
# app/avo/resources/project.rb
class Avo::Resources::Project < Avo::BaseResource
field :features,
as: :boolean_group,
options: -> do
record.features.each_with_object({}) do |feature, hash|
hash[feature.id] = feature.name.humanize
end
end
end
```

The output value must be a hash as described above.

:::

## Example DB payload
Expand Down

0 comments on commit 6a84f99

Please sign in to comment.