Class: Shoelace::Rails::Ui::FormHelper::ShoelaceInputField

Inherits:
ActionView::Helpers::Tags::TextField
  • Object
show all
Defined in:
app/helpers/shoelace/rails/ui/form_helper.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field_type, *args) ⇒ ShoelaceInputField

Returns a new instance of ShoelaceInputField.



33
34
35
36
# File 'app/helpers/shoelace/rails/ui/form_helper.rb', line 33

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.



31
32
33
# File 'app/helpers/shoelace/rails/ui/form_helper.rb', line 31

def field_type
  @field_type
end

Instance Method Details

#render(&block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/shoelace/rails/ui/form_helper.rb', line 38

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.fetch("invalid") { @object.errors[@method_name].presence }
  add_default_name_and_id(options)

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