diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-02 18:07:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-02 18:07:42 +0000 |
commit | 7b52c7cb634ef7047d30b0337fe477bcdcedf41d (patch) | |
tree | 374ca9e908204488422046f10e340d1500780362 /app/helpers | |
parent | b375c6c05fbd03aea33a9ee9f82e678bdaa8c3cc (diff) | |
download | gitlab-ce-7b52c7cb634ef7047d30b0337fe477bcdcedf41d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/form_helper.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb index bdb0a881b08..b611f700d21 100644 --- a/app/helpers/form_helper.rb +++ b/app/helpers/form_helper.rb @@ -3,18 +3,23 @@ module FormHelper prepend_if_ee('::EE::FormHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule - def form_errors(model, type: 'form') + def form_errors(model, type: 'form', truncate: []) return unless model.errors.any? 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 - model.errors.full_messages - .map { |msg| content_tag(:li, msg) } - .join - .html_safe + messages = model.errors.map do |attribute, message| + message = model.errors.full_message(attribute, message) + message = content_tag(:span, message, class: 'str-truncated-100') if truncate.include?(attribute) + + content_tag(:li, message) + end + + messages.join.html_safe end end end |