Class: Shoelace::Components::SlCheckbox

Inherits:
ActionView::Helpers::Tags::CheckBox
  • Object
show all
Includes:
ErrorWrappable
Defined in:
app/helpers/shoelace/components/sl_checkbox.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from ErrorWrappable

#error_wrapping

Instance Method Details

#render(&block) ⇒ Object



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
# File 'app/helpers/shoelace/components/sl_checkbox.rb', line 10

def render(&block)
  options = @options.stringify_keys
  options["value"]   = @checked_value
  options["checked"] = true if input_checked?(options)
  options["invalid"] = options["data-invalid"] = "" if object_has_errors?
  label = options.delete("label")

  if options["multiple"]
    add_default_name_and_id_for_value(@checked_value, options)
    options.delete("multiple")
  else
    add_default_name_and_id(options)
  end

  include_hidden = options.delete("include_hidden") { true }

  sl_checkbox_tag = if block_given?
                      @template_object.('sl-checkbox', '', options, &block)
                    else
                      @template_object.('sl-checkbox', label, options)
                    end

  if include_hidden
    hidden_field_for_checkbox(options) + sl_checkbox_tag
  else
    sl_checkbox_tag
  end
end