From 3cf09b476091c711d4ff6cb47a91bc8aaafe1a59 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 27 Feb 2023 12:54:21 +0000 Subject: [PATCH] feat: add initial question number behaviour --- app/helpers/question_view_helper.rb | 2 +- app/models/form/question.rb | 11 ++++++++++- app/models/form/sales/questions/ownership_scheme.rb | 1 + app/models/form/sales/questions/purchaser_code.rb | 1 + app/models/form/sales/questions/sale_date.rb | 1 + app/views/form/_textarea_question.html.erb | 2 +- 6 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/helpers/question_view_helper.rb b/app/helpers/question_view_helper.rb index fc308b835..3cfdec4c9 100644 --- a/app/helpers/question_view_helper.rb +++ b/app/helpers/question_view_helper.rb @@ -7,7 +7,7 @@ module QuestionViewHelper def legend(question, page_header, conditional) { - text: question.header.html_safe, + text: [question.question_number_string, question.header.html_safe].compact.join(" - "), size: label_size(page_header, conditional), tag: label_tag(page_header, conditional), } diff --git a/app/models/form/question.rb b/app/models/form/question.rb index fffa0059e..3bd0fd0ff 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -4,7 +4,7 @@ class Form::Question :conditional_for, :readonly, :answer_options, :page, :check_answer_label, :inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value, :guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived, - :check_answers_card_number, :unresolved_hint_text + :check_answers_card_number, :unresolved_hint_text, :question_number module GuidancePosition TOP = 1 @@ -40,6 +40,7 @@ class Form::Question @fields_added = hsh["fields_added"] @check_answers_card_number = hsh["check_answers_card_number"] || 0 @unresolved_hint_text = hsh["unresolved_hint_text"] + @question_number = hsh["question_number"] end end @@ -258,6 +259,14 @@ class Form::Question selected_answer_option_is_derived?(log) || has_inferred_check_answers_value?(log) end + def question_number_string + if @question_number + "Q#{@question_number}" + else + nil + end + end + private def selected_answer_option_is_derived?(log) diff --git a/app/models/form/sales/questions/ownership_scheme.rb b/app/models/form/sales/questions/ownership_scheme.rb index fc30ce3b4..dc1d4fb29 100644 --- a/app/models/form/sales/questions/ownership_scheme.rb +++ b/app/models/form/sales/questions/ownership_scheme.rb @@ -6,6 +6,7 @@ class Form::Sales::Questions::OwnershipScheme < ::Form::Question @header = "Was this purchase made through an ownership scheme?" @type = "radio" @answer_options = ANSWER_OPTIONS + @question_number = 3 end ANSWER_OPTIONS = { diff --git a/app/models/form/sales/questions/purchaser_code.rb b/app/models/form/sales/questions/purchaser_code.rb index 7a5cc4bf7..d288c9f5b 100644 --- a/app/models/form/sales/questions/purchaser_code.rb +++ b/app/models/form/sales/questions/purchaser_code.rb @@ -7,5 +7,6 @@ class Form::Sales::Questions::PurchaserCode < ::Form::Question @hint_text = "This is how you usually refer to the purchaser on your own systems." @type = "text" @width = 10 + @question_number = 2 end end diff --git a/app/models/form/sales/questions/sale_date.rb b/app/models/form/sales/questions/sale_date.rb index ce085b646..735872a6c 100644 --- a/app/models/form/sales/questions/sale_date.rb +++ b/app/models/form/sales/questions/sale_date.rb @@ -5,5 +5,6 @@ class Form::Sales::Questions::SaleDate < ::Form::Question @check_answer_label = "Sale completion date" @header = "What is the sale completion date?" @type = "date" + @question_number = 1 end end diff --git a/app/views/form/_textarea_question.html.erb b/app/views/form/_textarea_question.html.erb index a9768e4d0..a7ce882de 100644 --- a/app/views/form/_textarea_question.html.erb +++ b/app/views/form/_textarea_question.html.erb @@ -2,7 +2,7 @@ <%= f.govuk_text_area question.id.to_sym, caption: caption(caption_text, page_header, conditional), - label: legend(question, page_header, conditional), + label: legend(question, page_header, conditional, @log), hint: { text: question.hint_text&.html_safe }, width: question.width || nil, **stimulus_html_attributes(question) %>