Class: Formstrap::CheckboxView

Inherits:
ViewModel show all
Includes:
Hintable, Labelable, Validatable, Wrappable
Defined in:
app/models/formstrap/checkbox_view.rb

Instance Method Summary collapse

Methods inherited from ViewModel

#attributes, #initialize, #to_hash

Constructor Details

This class inherits a constructor from ViewModel

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ViewModel

Instance Method Details

#checked_valueObject



8
9
10
# File 'app/models/formstrap/checkbox_view.rb', line 8

def checked_value
  @checked_value || "1"
end

#input_optionsObject



16
17
18
19
20
# File 'app/models/formstrap/checkbox_view.rb', line 16

def input_options
  keys = attributes - %i[attribute form label validate wrapper checked_value unchecked_value]
  options = to_h.slice(*keys)
  default_input_options.deep_merge(options)
end

#label_optionsObject



22
23
24
25
26
27
28
29
30
# File 'app/models/formstrap/checkbox_view.rb', line 22

def label_options
  {
    class: ["form-check-label"],
    attribute: attribute,
    form: form,
    required: required,
    text: label
  }
end

#unchecked_valueObject



12
13
14
# File 'app/models/formstrap/checkbox_view.rb', line 12

def unchecked_value
  @unchecked_value || "0"
end

#wrapper_optionsObject



32
33
34
35
36
37
38
# File 'app/models/formstrap/checkbox_view.rb', line 32

def wrapper_options
  default_wrapper_options.deep_merge(
    {
      class: %w[form-check mb-3]
    }
  ).deep_merge(@wrapper || {})
end