diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 18:25:58 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 18:25:58 +0000 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /app/helpers/form_helper.rb | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) | |
download | gitlab-ce-a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4.tar.gz |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'app/helpers/form_helper.rb')
-rw-r--r-- | app/helpers/form_helper.rb | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb index cf3e99eee49..9b4d0c0b9b3 100644 --- a/app/helpers/form_helper.rb +++ b/app/helpers/form_helper.rb @@ -2,19 +2,29 @@ module FormHelper def form_errors(model, type: 'form', truncate: []) - return unless model.errors.any? + errors = model.errors + + return unless errors.any? + + headline = n_( + 'The %{type} contains the following error:', + 'The %{type} contains the following errors:', + errors.count + ) % { type: type } - headline = n_('The %{type} contains the following error:', 'The %{type} contains the following errors:', model.errors.count) % { type: type } truncate = Array.wrap(truncate) - content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do - content_tag(:h4, headline) << - content_tag(:ul) do - messages = model.errors.map do |attribute, message| - message = html_escape_once(model.errors.full_message(attribute, message)).html_safe - message = content_tag(:span, message, class: 'str-truncated-100') if truncate.include?(attribute) + tag.div(class: 'alert alert-danger', id: 'error_explanation') do + tag.h4(headline) << + tag.ul do + messages = errors.map do |error| + attribute = error.attribute + message = error.message + + message = html_escape_once(errors.full_message(attribute, message)).html_safe + message = tag.span(message, class: 'str-truncated-100') if truncate.include?(attribute) - content_tag(:li, message) + tag.li(message) end messages.join.html_safe |