diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 808edca91..2fd6a432d 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -47,6 +47,7 @@ class FormController < ApplicationController flash[:log_data] = responses_for_page question_ids = (@log.errors.map(&:attribute) - [:base]).uniq flash[:pages_with_errors_count] = question_ids.map { |id| @log.form.get_question(id, @log)&.page&.id }.compact.uniq.count + flash[:related_question_ids] = question_ids.map(&:to_s) redirect_to send("#{@log.log_type}_#{@page.id}_path", @log, { referrer: request.params["referrer"], original_page_id: request.params["original_page_id"], related_question_ids: request.params["related_question_ids"] }) end else @@ -91,13 +92,14 @@ class FormController < ApplicationController @pages_with_errors_count = 0 if @page.routed_to?(@log, current_user) || is_referrer_type?("interruption_screen") || adding_answer_from_check_errors_page? if updated_answer_from_check_errors_page? - @questions = request.params["related_question_ids"].map { |id| @log.form.get_question(id, @log) } + @questions = request.params["related_question_ids"].map { |id| @log.form.get_question(id, @log) }.compact render "form/check_errors" else if flash[:errors].present? restore_previous_errors(flash[:errors]) restore_error_field_values(flash[:log_data]) @pages_with_errors_count = flash[:pages_with_errors_count] + @related_question_ids = flash[:related_question_ids] end render "form/page" end diff --git a/app/views/form/page.html.erb b/app/views/form/page.html.erb index 54c1d68ab..8eeaa1ca4 100644 --- a/app/views/form/page.html.erb +++ b/app/views/form/page.html.erb @@ -77,7 +77,7 @@ <% if @pages_with_errors_count > 1 %>
- <%= f.submit "See all related answers", class: "govuk-body govuk-link submit-button-link" %> + <%= govuk_link_to "See all related answers", send("#{@log.log_type}_#{@page.id}_path", @log, check_errors: true, related_question_ids: @related_question_ids) %>
<% end %>