Class: ExpressTemplates::Components::Forms::SelectCollection

Inherits:
Select show all
Defined in:
lib/express_templates/components/forms/select_collection.rb

Overview

Provides a form Select component based on the Rails collection_select helper.

Constant Summary

Constants inherited from Base

Base::MAP

Instance Attribute Summary

Attributes inherited from FormComponent

#input_attributes

Instance Method Summary collapse

Methods inherited from Select

#field_name_attribute, #generate_options_from_field_values, #normalize_for_helper, #options_from_belongs_to, #options_from_has_many_through, #options_from_supplied_or_field_values, #select_helper_options, #select_options, #select_options_supplied?, #select_tag_args, #selected_value, #simple_options_with_selection, #use_supplied_options

Methods included from OptionSupport

#belongs_to_association, #has_many_through_association, #related_collection

Methods inherited from FormComponent

#field_helper_options, #field_id_attribute, #field_name, #field_name_attribute, #field_value, #label_name, #label_text, #parent_form, #resource, #resource_class, #resource_name

Methods included from Capabilities::Configurable

included

Methods inherited from Base

abstract_component, abstract_component?, before_build, #build, builder_method, builder_method_and_class, contains, descendants, has_attributes, inherited, #initialize, require_parent, required_parent, tag

Constructor Details

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

Instance Method Details

#collection_select_tag_argsObject



18
19
20
21
22
23
24
# File 'lib/express_templates/components/forms/select_collection.rb', line 18

def collection_select_tag_args
  [ resource_name,
    multi_field_name,
    related_collection, :id, :name,
    field_options,
    html_options ]
end

#field_optionsObject



26
27
28
# File 'lib/express_templates/components/forms/select_collection.rb', line 26

def field_options
  {include_blank: !!input_attributes.delete(:include_blank)}
end

#html_optionsObject



30
31
32
# File 'lib/express_templates/components/forms/select_collection.rb', line 30

def html_options
  input_attributes.reject {|k,v| k.eql?(:include_blank)}.merge(multiple: config[:multiple])
end

#multi_field_nameObject



34
35
36
37
38
39
40
# File 'lib/express_templates/components/forms/select_collection.rb', line 34

def multi_field_name
  if has_many_through_association
    "#{field_name.singularize}_ids"
  else
    raise "Only use select_collection for has_many :through.  #{field_name} is not has_many :through"
  end
end