Class: Trestle::Form::Fields::CollectionRadioButtons

Inherits:
Trestle::Form::Field show all
Defined in:
lib/trestle/form/fields/collection_radio_buttons.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, #render

Constructor Details

#initialize(builder, template, name, collection, value_method, text_method, options = {}, html_options = {}) ⇒ CollectionRadioButtons

Returns a new instance of CollectionRadioButtons.



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

def initialize(builder, template, name, collection, value_method, text_method, options={}, html_options={})
  super(builder, template, name, options)

  @collection, @value_method, @text_method = collection, value_method, text_method
  @html_options = default_html_options.merge(html_options)
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



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

def collection
  @collection
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



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

def html_options
  @html_options
end

#text_methodObject (readonly)

Returns the value of attribute text_method.



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

def text_method
  @text_method
end

#value_methodObject (readonly)

Returns the value of attribute value_method.



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

def value_method
  @value_method
end

Instance Method Details

#default_html_optionsObject



22
23
24
# File 'lib/trestle/form/fields/collection_radio_buttons.rb', line 22

def default_html_options
  Trestle::Options.new
end

#fieldObject



14
15
16
17
18
19
20
# File 'lib/trestle/form/fields/collection_radio_buttons.rb', line 14

def field
  (:div, class: "radio-buttons") do
    builder.raw_collection_radio_buttons(name, collection, value_method, text_method, options, html_options) do |b|
      b.label(class: "radio-inline") { b.radio_button + b.text }
    end
  end
end