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

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

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

Methods inherited from Trestle::Form::Field

#errors, #form_group, #normalize_options!, #readonly?, #render

Constructor Details

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

Returns a new instance of CollectionRadioButtons.



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

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

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



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

def collection
  @collection
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



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

def html_options
  @html_options
end

#text_methodObject (readonly)

Returns the value of attribute text_method.



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

def text_method
  @text_method
end

#value_methodObject (readonly)

Returns the value of attribute value_method.



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

def value_method
  @value_method
end

Instance Method Details

#default_html_optionsObject



32
33
34
# File 'lib/trestle/form/fields/collection_radio_buttons.rb', line 32

def default_html_options
  Trestle::Options.new
end

#defaultsObject



28
29
30
# File 'lib/trestle/form/fields/collection_radio_buttons.rb', line 28

def defaults
  super.merge(inline: true)
end

#fieldObject



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

def field
  builder.raw_collection_radio_buttons(name, collection, value_method, text_method, options, html_options) do |b|
    if block
      block.call(b)
    else
      (:div, class: default_wrapper_class) do
        b.radio_button(class: input_class) + b.label(class: label_class) { b.text }
      end
    end
  end
end