Radio button
There can be only one.
Includes a Ruby component and corresponding Rails helper
RubyForm use
To use in forms, it's easiest to use the Form Builder.
f.radio_button
tries to match Rails' own API.
For extra convenience use the f.field
method.
<%= nk_form_for @golem do |f| %>
<%= f.field :element,
options: Element.pluck(:name, :slug),
as: :radio_group,
label: "Golem type",
description: "He'll be invincible" %>
<% end %>
With a label
To add a label, use the label:
argument.
<%= nk_radio_button label: "Accept your fate" %>
Radio button group
Display multiple related radio buttons in a group under the same title.
<%= nk_radio_button_group value: "zero" do |g| %>
<%= g.title "Choose your poison" %>
<%= g.item name: "poison", value: "coke", label: "Coke" %>
<%= g.item name: "poison", value: "zero", label: "Coke Zero" %>
<% end %>
Usage
NB: While radio_button
supports Rails' API, using f.field
is recommended.
| ||
---|---|---|
Property | Default | Description |
compat_object_name | nil | API compatibility Relevant object |
compat_method | nil | API compatibility Object attribute |
compat_tag_value | nil | API compatibility Value of attribute |
compat_options | {} | API compatibility Options for radio button |
label | nil | Text label for radio button |
**attrs | HTML attributes for <input> element |