Class: Trestle::Form::Fields::RadioButton

Inherits:
Trestle::Form::Field show all
Defined in:
lib/trestle/form/fields/radio_button.rb

Instance Attribute Summary collapse

Attributes inherited from Trestle::Form::Field

#block, #builder, #name, #options, #template

Instance Method Summary collapse

Methods inherited from Trestle::Form::Field

#defaults, #errors, #extract_options!, #form_group

Constructor Details

#initialize(builder, template, name, tag_value, options = {}) ⇒ RadioButton

Returns a new instance of RadioButton.



7
8
9
10
11
# File 'lib/trestle/form/fields/radio_button.rb', line 7

def initialize(builder, template, name, tag_value, options={})
  super(builder, template, name, options)

  @tag_value = tag_value
end

Instance Attribute Details

#tag_valueObject (readonly)

Returns the value of attribute tag_value.



5
6
7
# File 'lib/trestle/form/fields/radio_button.rb', line 5

def tag_value
  @tag_value
end

Instance Method Details

#fieldObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/trestle/form/fields/radio_button.rb', line 17

def field
  (:div, class: "radio") do
    (:label) do
      safe_join([
        builder.raw_radio_button(name, tag_value, options),
        options[:label] || tag_value.to_s.humanize
      ], " ")
    end
  end
end

#renderObject



13
14
15
# File 'lib/trestle/form/fields/radio_button.rb', line 13

def render
  field
end