Module: GovukDesignSystem::ErrorSummaryHelper

Defined in:
app/helpers/govuk_design_system/error_summary_helper.rb

Instance Method Summary collapse

Instance Method Details

#govukErrorSummary(kwargs = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/govuk_design_system/error_summary_helper.rb', line 3

def govukErrorSummary(kwargs = {})
  form = kwargs[:form]

  if form.present?
    errors = kwargs[:errors] || form.object.errors
    return unless errors.try(:any?)

    kwargs[:titleText] = "There is a problem"
    kwargs[:errorList] = errors.details.keys.flat_map do |attribute|
      prefix = get_attribute_id_prefix(form, attribute)
      errors.full_messages_for(attribute).map { |m| { text: m, href: "##{prefix}-error" } }
    end
  end

  render "components/govuk_error_summary", **kwargs
end