Class: Decidim::ValidationErrorsPresenter

Inherits:
SimpleDelegator
  • Object
show all
Includes:
SanitizeHelper
Defined in:
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

Methods included from SanitizeHelper

#decidim_escape_translated, #decidim_html_escape, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_sanitize_translated, #decidim_url_escape, included

Constructor Details

#initialize(error, form) ⇒ ValidationErrorsPresenter

Returns a new instance of ValidationErrorsPresenter.



12
13
14
15
# File '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 '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 'app/presenters/decidim/validation_errors_presenter.rb', line 10

def form
  @form
end

Instance Method Details

#messageObject



17
18
19
# File '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 '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