Class: ExpressTemplates::Components::Forms::Radio
- Inherits:
-
FormComponent
- Object
- Arbre::Component
- Base
- Configurable
- FormComponent
- ExpressTemplates::Components::Forms::Radio
- Includes:
- OptionSupport
- Defined in:
- lib/express_templates/components/forms/radio.rb
Instance Attribute Summary
Attributes inherited from FormComponent
Instance Method Summary collapse
- #collection_from_association ⇒ Object
- #generate_options_from_specified_values ⇒ Object
- #option_collection ⇒ Object
- #option_values_specified? ⇒ Boolean
- #use_options_from_collection_radio_buttons_helper ⇒ Object
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_association ⇒ Object
58 59 60 |
# File 'lib/express_templates/components/forms/radio.rb', line 58 def collection_from_association or raise "No association collection for: #{resource_name}.#{field_name}" end |
#generate_options_from_specified_values ⇒ Object
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 case when option_collection.kind_of?(Array) option_collection.each_with_index do |option, index| label(class: config[:label_wrapper_class]) { (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]) { (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_collection ⇒ Object
33 34 35 |
# File 'lib/express_templates/components/forms/radio.rb', line 33 def option_collection config[:options] end |
#option_values_specified? ⇒ 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_helper ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/express_templates/components/forms/radio.rb', line 19 def (resource_var, field_name.to_sym, collection_from_association, option_value_method, option_name_method, input_attributes) do |b| b.label(class: "radio") { b. + b.text } end end |