Skip to content

Commit

Permalink
Add error items to flag the form elements on error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ana Botto committed Jun 27, 2024
1 parent 30833e2 commit 2be5e1a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/helpers/errors_helper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module ErrorsHelper
def errors_for(errors, attribute)
def errors_for(errors, attribute, use_full_message: true)
return nil if errors.blank?

errors.filter_map { |error|
if error.attribute == attribute
{
text: error.full_message,
text: use_full_message ? error.full_message : error.message,
}
end
}
.presence
.presence
end
end
2 changes: 2 additions & 0 deletions app/views/homepage/popular_links/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
name: "popular_links[#{index + 1}][title]",
id: "title#{index + 1}",
value: item[:title],
error_items: errors_for(form.object.errors, "title#{index + 1}".to_sym, use_full_message: false),
} %>

<%= render "govuk_publishing_components/components/input", {
Expand All @@ -19,4 +20,5 @@
name: "popular_links[#{index + 1}][url]",
id: "url#{index + 1}",
value: item[:url],
error_items: errors_for(form.object.errors, "url#{index + 1}".to_sym, use_full_message: false),
} %>

0 comments on commit 2be5e1a

Please sign in to comment.