Class: FoxTail::InputErrorListComponent

Inherits:
BaseComponent show all
Includes:
Concerns::Formable
Defined in:
app/components/fox_tail/input_error_list_component.rb

Instance Attribute Summary

Attributes inherited from BaseComponent

#html_attributes

Instance Method Summary collapse

Methods inherited from BaseComponent

classname_merger, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class

Methods inherited from Base

fox_tail_config

Constructor Details

#initialize(html_attributes = {}) ⇒ InputErrorListComponent

Returns a new instance of InputErrorListComponent.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/components/fox_tail/input_error_list_component.rb', line 16

def initialize(html_attributes = {})
  if (aliases = html_attributes.delete(:aliases)).present?
    html_attributes[:errors_for] = Array(html_attributes[:errors_for]) + Array(aliases)

    FoxTail.deprecator.allow ["aliases"] do
      callstack = Array(caller_locations[slot ? 7 : 4])
      FoxTail.deprecator.warn "The `aliases` option has been deprecated. Use `errors_for` instead.", callstack
    end
  end

  super
end

Instance Method Details

#before_renderObject



33
34
35
36
37
38
# File 'app/components/fox_tail/input_error_list_component.rb', line 33

def before_render
  super

  html_attributes[:class] = classnames theme.apply(:root, self), html_class
  error_messages.each { |msg| with_message msg } unless messages?
end

#callObject



40
41
42
43
44
# File 'app/components/fox_tail/input_error_list_component.rb', line 40

def call
   :ul, html_attributes do
    messages.each { |msg| concat msg }
  end
end

#render?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/components/fox_tail/input_error_list_component.rb', line 29

def render?
  messages? || error_messages.present?
end