Class: GOVUKDesignSystemFormBuilder::Elements::ErrorSummary

Inherits:
Base
  • Object
show all
Includes:
Traits::Error
Defined in:
lib/govuk_design_system_formbuilder/elements/error_summary.rb

Instance Method Summary collapse

Methods included from Traits::Error

#error_id

Constructor Details

#initialize(builder, object_name, title) ⇒ ErrorSummary

Returns a new instance of ErrorSummary.


6
7
8
9
10
# File 'lib/govuk_design_system_formbuilder/elements/error_summary.rb', line 6

def initialize(builder, object_name, title)
  @builder = builder
  @object_name = object_name
  @title = title
end

Instance Method Details

#htmlObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/govuk_design_system_formbuilder/elements/error_summary.rb', line 12

def html
  return nil unless object_has_errors?

  ('div', class: summary_class, **error_summary_attributes) do
    safe_join(
      [
        tag.h2(@title, id: error_summary_title_id, class: summary_class('title')),
        ('div', class: summary_class('body')) do
          ('ul', class: ['govuk-list', summary_class('list')]) do
            safe_join(
              @builder.object.errors.messages.map do |attribute, messages|
                error_list_item(attribute, messages.first)
              end
            )
          end
        end
      ]
    )
  end
end