diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 5c1c23c5b..1ddafa4e9 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -5,14 +5,14 @@ class FormController < ApplicationController def submit_form if @case_log - page = @case_log.form.get_page(params[:case_log][:page]) - responses_for_page = responses_for_page(page) + @page = @case_log.form.get_page(params[:case_log][:page]) + responses_for_page = responses_for_page(@page) if @case_log.update(responses_for_page) && @case_log.has_no_unresolved_soft_errors? - redirect_path = @case_log.form.next_page_redirect_path(page, @case_log) + redirect_path = @case_log.form.next_page_redirect_path(@page, @case_log) redirect_to(send(redirect_path, @case_log)) else - subsection = @case_log.form.subsection_for_page(page) - render "form/page", locals: { page: page, subsection: subsection.label }, status: :unprocessable_entity + @subsection = @case_log.form.subsection_for_page(@page) + render "form/page", status: :unprocessable_entity end else render_not_found @@ -33,9 +33,9 @@ class FormController < ApplicationController form.pages.map do |page| define_method(page.id) do |_errors = {}| if @case_log - subsection = @case_log.form.subsection_for_page(page) - case_log_form_page = @case_log.form.get_page(page.id) - render "form/page", locals: { page: case_log_form_page, subsection: subsection.label } + @subsection = @case_log.form.subsection_for_page(page) + @page = @case_log.form.get_page(page.id) + render "form/page" else render_not_found end diff --git a/app/views/form/_select_question.html.erb b/app/views/form/_select_question.html.erb index 0e321c991..f3a07ae4c 100644 --- a/app/views/form/_select_question.html.erb +++ b/app/views/form/_select_question.html.erb @@ -1,3 +1,4 @@ +<% selected = CaseLog::UK_LA[@case_log.public_send(question.id)] || "" %> <%= answers = question.answer_options.map { |key, value| OpenStruct.new(id: key, name: value) } f.govuk_collection_select question.id.to_sym, answers, @@ -6,6 +7,6 @@ caption: caption && !page_header.present? ? { text: caption.html_safe, size: "l" } : nil, label: { text: question.header, size: !page_header.present? ? "l" : "m", tag: !page_header.present? ? "h1" : "h2" }, hint: { text: question.hint_text&.html_safe }, - options: { disabled: [""], selected: @case_log.public_send(question.id) || "" }, + options: { disabled: [""], selected: selected }, "data-controller": "accessible-autocomplete" %> diff --git a/app/views/form/page.html.erb b/app/views/form/page.html.erb index 3be29bc31..8385eaac7 100644 --- a/app/views/form/page.html.erb +++ b/app/views/form/page.html.erb @@ -1,4 +1,8 @@ -<% content_for :title, page.header.present? ? page.header : page.questions.first().header.html_safe %> +<% content_for :head do %> + +<% end %> + +<% content_for :title, @page.header.present? ? @page.header : @page.questions.first().header.html_safe %> <% content_for :before_content do %> <%= govuk_back_link( @@ -10,26 +14,26 @@ <%= turbo_frame_tag "case_log_form", target: "_top" do %>