Method: Satis::Dropdown::Component#initialize

Defined in:
app/components/satis/dropdown/component.rb

#initialize(form:, attribute:, **options, &block) ⇒ Component

Returns a new instance of Component.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/components/satis/dropdown/component.rb', line 8

def initialize(form:, attribute:, **options, &block)
  super

  @form = form
  @attribute = attribute
  @title = title
  @options = options
  @url = options[:url]
  @chain_to = options[:chain_to]
  @free_text = options[:free_text]
  @needs_exact_match = options[:needs_exact_match]
  @reset_button = options[:reset_button] || options[:include_blank]

  options[:input_html] ||= {}
  options[:input_html][:value] = hidden_value

  options[:input_html][:autofocus] ||= false
  if options[:input_html][:autofocus]
    options[:autofocus] = 'autofocus'
    options[:input_html].delete(:autofocus)
  end

  actions = [options[:input_html]['data-action'], 'change->satis-dropdown#display',
             'focus->satis-dropdown#focus'].join(' ')

  options[:input_html].merge!('data-satis-dropdown-target' => 'hiddenInput',
                              'data-action' => actions)

  @block = block
  @page_size = options[:page_size] || 10
end