From c4b5dac3e61cf25281f6552980ff77f7770ac419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kry=C5=A1tof=20Korb?= Date: Fri, 12 Apr 2024 12:44:56 +0200 Subject: [PATCH] Add computed options to boolean group --- docs/3.0/fields/boolean_group.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/3.0/fields/boolean_group.md b/docs/3.0/fields/boolean_group.md index aea8c60b..a7bcae8e 100644 --- a/docs/3.0/fields/boolean_group.md +++ b/docs/3.0/fields/boolean_group.md @@ -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