Class: Superform::Rails::Components::Input

Inherits:
Field
  • Object
show all
Defined in:
lib/superform/rails/components/input.rb

Instance Attribute Summary

Attributes inherited from Base

#dom, #field

Instance Method Summary collapse

Methods inherited from Base

#focus, #initialize

Constructor Details

This class inherits a constructor from Superform::Rails::Components::Base

Instance Method Details

#field_attributesObject



9
10
11
12
13
14
15
16
# File 'lib/superform/rails/components/input.rb', line 9

def field_attributes
  {
    id: dom.id,
    name: dom.name,
    type: type,
    value: value
  }
end

#has_client_provided_value?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
# File 'lib/superform/rails/components/input.rb', line 18

def has_client_provided_value?
  case type.to_s
  when "file", "image"
    true
  else
    false
  end
end

#typeObject



31
32
33
# File 'lib/superform/rails/components/input.rb', line 31

def type
  @type ||= ActiveSupport::StringInquirer.new(attribute_type || value_type)
end

#valueObject



27
28
29
# File 'lib/superform/rails/components/input.rb', line 27

def value
  dom.value unless has_client_provided_value?
end

#view_templateObject



5
6
7
# File 'lib/superform/rails/components/input.rb', line 5

def view_template(&)
  input(**attributes)
end