Class: Practical::Views::Form::FieldErrorsComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/practical/views/form/field_errors_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(f:, object_method:, multiple_errors_blurb:, options:) ⇒ FieldErrorsComponent

Returns a new instance of FieldErrorsComponent.



6
7
8
9
10
11
# File 'app/components/practical/views/form/field_errors_component.rb', line 6

def initialize(f:, object_method:, multiple_errors_blurb:, options:)
  @f = f
  @object_method = object_method
  @multiple_errors_blurb = multiple_errors_blurb
  @options = options
end

Instance Attribute Details

#fObject (readonly)

Returns the value of attribute f.



4
5
6
# File 'app/components/practical/views/form/field_errors_component.rb', line 4

def f
  @f
end

#multiple_errors_blurbObject (readonly)

Returns the value of attribute multiple_errors_blurb.



4
5
6
# File 'app/components/practical/views/form/field_errors_component.rb', line 4

def multiple_errors_blurb
  @multiple_errors_blurb
end

#object_methodObject (readonly)

Returns the value of attribute object_method.



4
5
6
# File 'app/components/practical/views/form/field_errors_component.rb', line 4

def object_method
  @object_method
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'app/components/practical/views/form/field_errors_component.rb', line 4

def options
  @options
end

Instance Method Details

#errorsObject



13
14
15
# File 'app/components/practical/views/form/field_errors_component.rb', line 13

def errors
  f.errors_for(object_method) || []
end

#finalized_optionsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/components/practical/views/form/field_errors_component.rb', line 17

def finalized_options
  id = f.field_errors_id(object_method)
  classes = ["error-section"]

  if errors.blank?
    classes << ["no-server-errors"]
  end

  return mix({
    id: id,
    class: classes,
    data: {'pf-error-container': true}
  }, options)
end