Class: Shoelace::Components::SlInput

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ErrorWrappable

#error_wrapping

Constructor Details

#initialize(field_type, *args) ⇒ SlInput

Returns a new instance of SlInput.



12
13
14
15
# File 'app/helpers/shoelace/components/sl_input.rb', line 12

def initialize(field_type, *args)
  super(*args)
  @field_type = field_type
end

Instance Attribute Details

#field_typeObject (readonly)

Returns the value of attribute field_type.



10
11
12
# File 'app/helpers/shoelace/components/sl_input.rb', line 10

def field_type
  @field_type
end

Instance Method Details

#render(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/shoelace/components/sl_input.rb', line 17

def render(&block)
  options = @options.stringify_keys

  value = options.fetch("value") { value_before_type_cast }
  options["value"] = value if value.present?

  options["size"] = options["maxlength"] unless options.key?("size")
  options["type"] ||= field_type
  options["invalid"] = options["data-invalid"] = "" if object_has_errors?

  add_default_name_and_id(options)

  @template_object.('sl-input', '', options, &block)
end