Class: EnumRadioInput

Inherits:
SimpleForm::Inputs::CollectionRadioButtonsInput
  • Object
show all
Defined in:
app/inputs/enum_radio_input.rb

Overview

SimpleForm input wrapper: enum radio.

Direct Known Subclasses

YesNoInput

Instance Method Summary collapse

Constructor Details

#initialize(builder, attribute_name, column, input_type, options = {}) ⇒ EnumRadioInput

Renders an enum attribute as radio buttons, forcing input_type to :radio_buttons.
The collection is built from the model's enum keys (see #collection).

Parameters:

  • builder (SimpleForm::FormBuilder)

    the form builder

  • attribute_name (Symbol)

    the enum attribute name

  • column (Object)

    the column reflection (unused, forwarded to SimpleForm)

  • input_type (Symbol)

    overridden to :radio_buttons

  • options (Hash) (defaults to: {})

    SimpleForm input options, forwarded to the parent input

Options Hash (options):

  • collection (Array)

    overrides the auto-built enum collection

  • item_wrapper_class (String)

    CSS class applied to each radio wrapper

  • label_method (Symbol, Proc)

    method used to build each label

  • value_method (Symbol, Proc)

    method used to build each input value



15
16
17
18
# File 'app/inputs/enum_radio_input.rb', line 15

def initialize(builder, attribute_name, column, input_type, options = {})
  input_type = :radio_buttons
  super
end

Instance Method Details

#collectionObject (protected)



26
27
28
# File 'app/inputs/enum_radio_input.rb', line 26

def collection
  object.class.send(attribute_name.to_s.pluralize).keys.map { |k| [k.titleize, k] }
end

#input(wrapper_options = nil) ⇒ Object



20
21
22
# File 'app/inputs/enum_radio_input.rb', line 20

def input(wrapper_options = nil)
  super
end