Class: Decidim::ValidationErrorsPresenter

Inherits:
SimpleDelegator
  • Object
show all
Includes:
SanitizeHelper
Defined in:
decidim-core/app/presenters/decidim/validation_errors_presenter.rb

Overview

Decorator to format validation errors of a form in html format

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, form) ⇒ ValidationErrorsPresenter

Returns a new instance of ValidationErrorsPresenter.


12
13
14
15
# File 'decidim-core/app/presenters/decidim/validation_errors_presenter.rb', line 12

def initialize(error, form)
  @error = error
  @form = form
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.


10
11
12
# File 'decidim-core/app/presenters/decidim/validation_errors_presenter.rb', line 10

def error
  @error
end

#formObject (readonly)

Returns the value of attribute form.


10
11
12
# File 'decidim-core/app/presenters/decidim/validation_errors_presenter.rb', line 10

def form
  @form
end

Instance Method Details

#messageObject


17
18
19
# File 'decidim-core/app/presenters/decidim/validation_errors_presenter.rb', line 17

def message
  "<p>#{error}</p>#{validation_errors_list}"
end

#validation_errors_listObject


21
22
23
24
25
# File 'decidim-core/app/presenters/decidim/validation_errors_presenter.rb', line 21

def validation_errors_list
  return "" if form.valid?

  (:ul, decidim_sanitize(form.errors.full_messages.map { |err| (:li, err) }.join))
end