Radio API
Per-option reference for the Radio field. For tasks and examples, see the Radio guide.
Pass these options to a field declaration in your resource's fields method, for example in app/avo/resources/user.rb:
field :role, as: :radio, options: { admin: "Administrator", writer: "Writer" }For options shared by all fields, including default, visibility, and help text, see Field options.
Define choices
-> options
The available choices, with submitted values as keys and visible labels as values. Index and Show look up the stored value in this hash with indifferent access for string and symbol keys; a missing or falsey label falls back to the stored value. A nil field value displays a dash.
field :role, as: :radio, options: { admin: "Administrator", writer: "Writer" }- Type:
Hash, orProc/Lambdareturning aHash. - Default:
{} - Context: Callable options run in
Avo::ExecutionContextwithrecord,resource,view, andfield. - Validation: No explicit type validation. Forms iterate the result with
each; label lookup callswith_indifferent_access, so the result must support those operations.
On forms, a choice is checked when the field value matches either its key or its label after conversion to strings. A nil value checks no choice. This also applies to values supplied through the shared default option. Both form styles always submit the key, even when the current value matched a label.
Choice shape
Reversing keys and labels changes what is submitted. Integer keys remain integers during label lookup; they do not match stored strings such as "1", even though form checked-state matching compares strings. A callable must return a hash, not nil.
Control presentation
-> display_as
Selects the form control's appearance. Both styles use radio inputs and submit the option key. Index and Show are unchanged.
field :role, as: :radio, display_as: :tabs, options: { admin: "Administrator", writer: "Writer" }| Value | Behavior |
|---|---|
:radio | Standard radio buttons. |
:tabs | Tab-style switcher. |
- Type:
Symbol - Default:
:radio - Values:
:radio,:tabs - Validation: No enum validation. Only the symbol
:tabsenables tabs; all other values, including the string"tabs", render standard radio buttons.nilandfalsefall back to:radio.
-> display_value
Displays the stored field value on Index and Show instead of looking up its label in options. Form labels and submitted values are unchanged. A nil value still displays a dash.
field :role, as: :radio, display_value: true, options: { admin: "Administrator", writer: "Writer" }- Type:
Boolean - Default:
false
Ruby truthiness
This option uses Ruby truthiness, not Boolean string parsing. Only false and nil disable it; values such as "false" and 0 enable it.