Class: FoxTail::SelectComponent

Inherits:
InputBaseComponent show all
Includes:
Concerns::Choosable, Concerns::Placeholderable
Defined in:
app/components/fox_tail/select_component.rb

Instance Attribute Summary

Attributes inherited from BaseComponent

#html_attributes

Instance Method Summary collapse

Methods inherited from InputBaseComponent

stimulus_controller_name, #stimulus_controller_options, #use_stimulus?

Methods inherited from BaseComponent

classname_merger, #initialize, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class

Methods inherited from Base

fox_tail_config

Constructor Details

This class inherits a constructor from FoxTail::BaseComponent

Instance Method Details

#before_renderObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/components/fox_tail/select_component.rb', line 37

def before_render
  super

  html_attributes[:class] = classnames theme.apply(:root, self), html_class
  html_attributes[:multiple] = :multiple if html_attributes[:multiple]

  if placeholder?
    with_prompt retrieve_placeholder, selected: value_from_object.nil?
  elsif include_blank?
    with_prompt "", disabled: false, selected: value_from_object.nil?
  end

  add_choices
end

#callObject



52
53
54
55
56
57
# File 'app/components/fox_tail/select_component.rb', line 52

def call
  capture do
    concat render_hidden if html_attributes[:multiple].present? && include_hidden?
    concat render_select
  end
end

#valueObject



33
34
35
# File 'app/components/fox_tail/select_component.rb', line 33

def value
  options[:value] ||= value_before_type_cast
end