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

Inherits:
Trestle::Form::Field show all
Includes:
RadioButtonHelpers
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 included from RadioButtonHelpers

#default_wrapper_class, #inline?, #input_class, #label_class

Methods inherited from Trestle::Form::Field

#defaults, #disabled?, #errors, #form_group, #normalize_options!, #readonly?

Constructor Details

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

Returns a new instance of RadioButton.



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

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.



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

def tag_value
  @tag_value
end

Instance Method Details

#extract_wrapper_options!Object



31
32
33
# File 'lib/trestle/form/fields/radio_button.rb', line 31

def extract_wrapper_options!
  # Intentional no-op
end

#fieldObject



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

def field
  wrapper_class = options.delete(:class)
  wrapper_class = default_wrapper_class if wrapper_class.empty?

  tag.div(class: wrapper_class) do
    safe_join([
      builder.raw_radio_button(name, tag_value, options.merge(class: input_class)),
      builder.label(name, options[:label] || tag_value.to_s.humanize, value: tag_value, class: label_class)
    ])
  end
end

#renderObject



15
16
17
# File 'lib/trestle/form/fields/radio_button.rb', line 15

def render
  field
end