Class: ViewComponent::Form::CollectionSelectComponent

Inherits:
FieldComponent show all
Defined in:
app/components/view_component/form/collection_select_component.rb

Instance Attribute Summary collapse

Attributes inherited from FieldComponent

#method_name

Attributes inherited from BaseComponent

#form, #object_name, #options

Instance Method Summary collapse

Methods inherited from FieldComponent

#label_text, #method_errors, #method_errors?, #object_method_names, #optional?, #required?, #validators, #value

Methods inherited from BaseComponent

#html_class, #object_errors, #object_errors?

Methods included from ClassNamesHelper

#build_tag_values, #class_names

Constructor Details

#initialize(form, object_name, method_name, collection, value_method, text_method, options = {}, html_options = {}) ⇒ CollectionSelectComponent

rubocop:disable Metrics/ParameterLists



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/components/view_component/form/collection_select_component.rb', line 8

def initialize( # rubocop:disable Metrics/ParameterLists
  form,
  object_name,
  method_name,
  collection,
  value_method,
  text_method,
  options = {},
  html_options = {}
)
  @collection = collection
  @value_method = value_method
  @text_method = text_method
  @html_options = html_options

  super(form, object_name, method_name, options)

  set_html_options!
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



6
7
8
# File 'app/components/view_component/form/collection_select_component.rb', line 6

def collection
  @collection
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



6
7
8
# File 'app/components/view_component/form/collection_select_component.rb', line 6

def html_options
  @html_options
end

#text_methodObject (readonly)

Returns the value of attribute text_method.



6
7
8
# File 'app/components/view_component/form/collection_select_component.rb', line 6

def text_method
  @text_method
end

#value_methodObject (readonly)

Returns the value of attribute value_method.



6
7
8
# File 'app/components/view_component/form/collection_select_component.rb', line 6

def value_method
  @value_method
end

Instance Method Details

#callObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/components/view_component/form/collection_select_component.rb', line 28

def call
  ActionView::Helpers::Tags::CollectionSelect.new(
    object_name,
    method_name,
    @view_context,
    collection,
    value_method,
    text_method,
    options,
    html_options
  ).render
end