Method: Satis::Switch::Component#initialize

Defined in:
app/components/satis/switch/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
# File 'app/components/satis/switch/component.rb', line 8

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

  @form = form
  @attribute = attribute
  @options = options
  @block = block
  @icon = true
  @icon = options[:icon] if options.key?(:icon)
  @value = options.key?(:value) ? options[:value] : @form.object.send(attribute)
  @value = @value == '0' || !@value ? false : true
  options[:input_html] ||= {}
  options[:input_html] = { data: { 'satis-switch-target' => 'hiddenInput' } }.deep_merge(options[:input_html])
end