Radio
The Radio field is used to render radio buttons. It's useful when only one value can be selected in a given options group.
Field declaration example
Below is an example of declaring a radio field for a role:
field :role,
as: :radio,
name: "User role",
options: {
admin: "Administrator",
manager: "Manager",
writer: "Writer"
}Options
-> options
The options attribute accepts either a Hash or a proc, allowing the incorporation of custom logic. Within this block, you gain access to all attributes of Avo::ExecutionContext along with the record, resource, view and field.
This attribute represents the options that should be displayed in the radio buttons.
Default value
Empty Hash.
{}Possible values
Any Hash. The keys represent the value that will be persisted and the values are the visible labels. Example:
options: {
admin: "Administrator",
manager: "Manager",
writer: "Writer"
}Or a Proc:
options: -> do
record.roles.each_with_object({}) do |role, hash|
hash[role.id] = role.name.humanize
end
end-> display_as
Controls how the radio buttons are rendered. When set to :tabs, the options are displayed as a tab-style switcher instead of standard radio buttons.
Default value
:radio
Possible values
:radio, :tabs
field :role, as: :radio, display_as: :tabs, options: { admin: "Administrator", writer: "Writer" }