Radio button

There can be only one.
Includes a Ruby component and corresponding Rails helper
Ruby

Example

<%= nk_radio_button "name", "value" %>

API tries to match Rails' own radio_button() helper.

Form 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.

He'll be invincible
<%= 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.

nk_radio_button(
  compat_object_name = nil,
  compat_method = nil,
  compat_tag_value = nil,
  compat_options = {},
  label: nil,
  **attrs
)
PropertyDefaultDescription
compat_object_namenil API compatibility Relevant object
compat_methodnil API compatibility Object attribute
compat_tag_valuenil API compatibility Value of attribute
compat_options{} API compatibility Options for radio button
labelnil Text label for radio button
**attrsHTML attributes for <input> element