|
|
|
@ -38,8 +38,14 @@ class FormController < ApplicationController
|
|
|
|
|
error_attributes = @log.errors.map(&:attribute) |
|
|
|
|
Rails.logger.info "User triggered validation(s) on: #{error_attributes.join(', ')}" |
|
|
|
|
@subsection = form.subsection_for_page(@page) |
|
|
|
|
flash[:errors] = @log.errors |
|
|
|
|
flash[:errors] = @log.errors.each_with_object({}) do |error, result| |
|
|
|
|
if @page.questions.map(&:id).include?(error.attribute.to_s) |
|
|
|
|
result[error.attribute.to_s] = error.message |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
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 |
|
|
|
|
redirect_to send("#{@log.class.name.underscore}_#{@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 |
|
|
|
@ -81,6 +87,7 @@ class FormController < ApplicationController
|
|
|
|
|
page_id = request.path.split("/")[-1].underscore |
|
|
|
|
@page = form.get_page(page_id) |
|
|
|
|
@subsection = form.subsection_for_page(@page) |
|
|
|
|
@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) } |
|
|
|
@ -89,6 +96,7 @@ class FormController < ApplicationController
|
|
|
|
|
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] |
|
|
|
|
end |
|
|
|
|
render "form/page" |
|
|
|
|
end |
|
|
|
@ -121,7 +129,7 @@ private
|
|
|
|
|
return unless previous_errors |
|
|
|
|
|
|
|
|
|
previous_errors.each do |attribute, message| |
|
|
|
|
@log.errors.add attribute, message.first |
|
|
|
|
@log.errors.add attribute, message.html_safe |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|