Class: ExpressTemplates::Components::Forms::Radio

Inherits:
FormComponent show all
Includes:
OptionSupport
Defined in:
lib/express_templates/components/forms/radio.rb

Instance Attribute Summary

Attributes inherited from FormComponent

#input_attributes

Instance Method Summary collapse

Methods included from OptionSupport

#belongs_to_association, #has_many_through_association, #related_collection

Methods inherited from FormComponent

#field_name, #field_name_attribute, #label_name, #label_text, #parent_form, #resource_class, #resource_name, #resource_var

Methods inherited from Configurable

#build, #config, emits, has_argument, has_option, #required_options

Methods inherited from Base

before_build, #build, builder_method_and_class, #builder_method_name, builder_method_name, contains, descendants, has_attributes, inherited, #initialize, #resource, tag

Constructor Details

This class inherits a constructor from ExpressTemplates::Components::Base

Instance Method Details

#collection_from_associationObject



58
59
60
# File 'lib/express_templates/components/forms/radio.rb', line 58

def collection_from_association
  related_collection or raise "No association collection for: #{resource_name}.#{field_name}"
end

#generate_options_from_specified_valuesObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/express_templates/components/forms/radio.rb', line 37

def generate_options_from_specified_values
  case
  when option_collection.kind_of?(Array)
    option_collection.each_with_index do |option, index|
      label(class: config[:label_wrapper_class]) {
        radio_button(resource_var, field_name.to_sym, option, class: 'radio')
        current_arbre_element.add_child option
      }
    end
  when option_collection.kind_of?(Hash)
    option_collection.each_pair do |key, value|
      label(class: config[:label_wrapper_class]) {
        radio_button(resource_var, field_name.to_sym, key, class: 'radio')
        current_arbre_element.add_child  value
      }
    end
  else
    raise "Radio collection should be Array or Hash: #{option_collection.inspect}"
  end
end

#option_collectionObject



33
34
35
# File 'lib/express_templates/components/forms/radio.rb', line 33

def option_collection
  config[:options]
end

#option_values_specified?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/express_templates/components/forms/radio.rb', line 29

def option_values_specified?
  [Array, Hash].include?(option_collection.class)
end

#use_options_from_collection_radio_buttons_helperObject



19
20
21
22
23
24
25
26
27
# File 'lib/express_templates/components/forms/radio.rb', line 19

def use_options_from_collection_radio_buttons_helper
  collection_radio_buttons(resource_var, field_name.to_sym, collection_from_association,
                           option_value_method, option_name_method,
                           input_attributes) do |b|
    b.label(class: "radio") {
      b.radio_button + b.text
    }
  end
end