Class: Yattho::Forms::CheckBox

Inherits:
BaseComponent show all
Defined in:
lib/yattho/forms/check_box.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes included from ActsAsComponent

#template_root_path

Instance Method Summary collapse

Methods inherited from BaseComponent

#content, inherited, #input?, #perform_render, #render?, #to_component, #type

Methods included from ActsAsComponent

#compile!, extended, #renders_templates

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(input:) ⇒ CheckBox

Returns a new instance of CheckBox.



9
10
11
12
13
14
15
16
17
18
# File 'lib/yattho/forms/check_box.rb', line 9

def initialize(input:)
  @input = input
  @input.add_label_classes("FormControl-label")
  @input.add_input_classes("FormControl-checkbox")

  return unless @input.scheme == :array

  @input.input_arguments[:multiple] = true
  @input.label_arguments[:value] = checked_value
end

Instance Method Details

#nested_form_argumentsObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/yattho/forms/check_box.rb', line 20

def nested_form_arguments
  return @nested_form_arguments if defined?(@nested_form_arguments)

  @nested_form_arguments = { hidden: @input.hidden?, **@input.nested_form_arguments }
  @nested_form_arguments[:class] = class_names(
    @nested_form_arguments[:class],
    @nested_form_arguments.delete(:classes),
    "ml-4"
  )

  @nested_form_arguments
end