Class: Forme::ErrorHandler::AfterLegend

Inherits:
Forme::ErrorHandler show all
Defined in:
lib/forme/transformers/error_handler.rb

Instance Method Summary collapse

Instance Method Details

#call(tag, input) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/forme/transformers/error_handler.rb', line 51

def call(tag, input)
  if tag.is_a?(Array) && tag.first.is_a?(Tag) && tag.first.type == :legend
    first_input = input.opts[:first_input]
    attr = first_input.opts[:attr] ||= {}
    Forme.attr_classes(attr, 'error')
    attr['aria-invalid'] = 'true'
    attr['aria-describedby'] = input.opts[:error_id] = "#{first_input.opts[:id]}_error_message"

    tag.insert(1, error_tag(input))
  else
    super 
  end
end