Class: ViewComponent::Form::BaseComponent

Inherits:
Object
  • Object
show all
Includes:
ClassNamesHelper
Defined in:
app/components/view_component/form/base_component.rb

Direct Known Subclasses

ButtonComponent, FieldComponent, SubmitComponent

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassNamesHelper

#build_tag_values, #class_names

Constructor Details

#initialize(form, object_name, options = {}) ⇒ BaseComponent

Returns a new instance of BaseComponent.



16
17
18
19
20
21
22
23
24
# File 'app/components/view_component/form/base_component.rb', line 16

def initialize(form, object_name, options = {})
  @form = form

  # See: https://github.com/rails/rails/blob/83217025a171593547d1268651b446d3533e2019/actionview/lib/action_view/helpers/tags/base.rb#L13
  @object_name = object_name.to_s.dup
  @options     = options

  super()
end

Class Attribute Details

.default_optionsObject

Returns the value of attribute default_options.



7
8
9
# File 'app/components/view_component/form/base_component.rb', line 7

def default_options
  @default_options
end

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



12
13
14
# File 'app/components/view_component/form/base_component.rb', line 12

def form
  @form
end

#object_nameObject (readonly)

Returns the value of attribute object_name.



12
13
14
# File 'app/components/view_component/form/base_component.rb', line 12

def object_name
  @object_name
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'app/components/view_component/form/base_component.rb', line 12

def options
  @options
end

Instance Method Details

#html_classObject



38
39
40
# File 'app/components/view_component/form/base_component.rb', line 38

def html_class
  nil
end

#object_errorsObject



32
33
34
35
36
# File 'app/components/view_component/form/base_component.rb', line 32

def object_errors
  return nil unless object

  object.errors
end

#object_errors?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'app/components/view_component/form/base_component.rb', line 26

def object_errors?
  return false unless object

  object.errors.any?
end