From 4e85707b8c8611abe731e939abdcbe886d407cdf Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Tue, 11 Apr 2023 12:05:25 +0100 Subject: [PATCH] remove list of question ids from the form that should not be cleared, this information should be held on the questions themselves --- app/models/form.rb | 6 ++---- app/models/form/lettings/questions/address_line1.rb | 1 + app/models/form/lettings/questions/address_line2.rb | 1 + app/models/form/lettings/questions/county.rb | 1 + app/models/form/lettings/questions/la.rb | 1 + app/models/form/lettings/questions/location_id.rb | 6 ++++-- .../form/lettings/questions/postcode_for_full_address.rb | 1 + app/models/form/lettings/questions/postcode_full.rb | 1 + app/models/form/lettings/questions/postcode_known.rb | 1 + app/models/form/lettings/questions/ppcodenk.rb | 1 + app/models/form/lettings/questions/ppostcode_full.rb | 1 + app/models/form/lettings/questions/previous_la_known.rb | 1 + app/models/form/lettings/questions/prevloc.rb | 1 + app/models/form/lettings/questions/town_or_city.rb | 1 + app/models/form/question.rb | 3 ++- app/models/form/sales/pages/extra_borrowing_value_check.rb | 3 +-- app/models/form/sales/questions/address_line1.rb | 1 + app/models/form/sales/questions/address_line2.rb | 1 + app/models/form/sales/questions/county.rb | 1 + app/models/form/sales/questions/postcode.rb | 1 + .../form/sales/questions/postcode_for_full_address.rb | 1 + app/models/form/sales/questions/previous_la_known.rb | 1 + app/models/form/sales/questions/previous_postcode.rb | 1 + app/models/form/sales/questions/previous_postcode_known.rb | 1 + app/models/form/sales/questions/prevloc.rb | 1 + .../form/sales/questions/property_local_authority.rb | 1 + app/models/form/sales/questions/town_or_city.rb | 1 + config/forms/2021_2022.json | 7 +++++++ config/forms/2022_2023.json | 7 +++++++ spec/fixtures/forms/2021_2022.json | 6 ++++++ 30 files changed, 52 insertions(+), 9 deletions(-) diff --git a/app/models/form.rb b/app/models/form.rb index e862a9c85..8c558ca34 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -238,12 +238,10 @@ class Form end def routed_and_not_routed_questions_by_type(log, type: nil, current_user: nil) - # we're already treating these fields as a special case and reset their values upon saving a log - callback_questions = %w[postcode_known la ppcodenk previous_la_known prevloc postcode_full ppostcode_full location_id address_line1 address_line2 town_or_city county] questions_to_categorise = if type - questions.reject { |q| q.type != type || callback_questions.include?(q.id) } + questions.reject { |q| q.type != type || q.do_not_clear } else - questions.reject { |q| %w[radio checkbox].include?(q.type) || callback_questions.include?(q.id) } + questions.reject { |q| %w[radio checkbox].include?(q.type) || q.do_not_clear } end valid, invalid = questions_to_categorise.partition { |q| q.page.routed_to?(log, current_user) || q.derived? } { valid:, invalid: } diff --git a/app/models/form/lettings/questions/address_line1.rb b/app/models/form/lettings/questions/address_line1.rb index 4c8b4151b..dcac5c7ae 100644 --- a/app/models/form/lettings/questions/address_line1.rb +++ b/app/models/form/lettings/questions/address_line1.rb @@ -7,6 +7,7 @@ class Form::Lettings::Questions::AddressLine1 < ::Form::Question @type = "text" @plain_label = true @check_answer_label = "Q12 - Address" + @do_not_clear = true end def answer_label(log, _current_user = nil) diff --git a/app/models/form/lettings/questions/address_line2.rb b/app/models/form/lettings/questions/address_line2.rb index 16f7c8336..34a845745 100644 --- a/app/models/form/lettings/questions/address_line2.rb +++ b/app/models/form/lettings/questions/address_line2.rb @@ -5,6 +5,7 @@ class Form::Lettings::Questions::AddressLine2 < ::Form::Question @header = "Address line 2 (optional)" @type = "text" @plain_label = true + @do_not_clear = true end def hidden_in_check_answers?(_log = nil, _current_user = nil) diff --git a/app/models/form/lettings/questions/county.rb b/app/models/form/lettings/questions/county.rb index 360c0966c..bea234cf1 100644 --- a/app/models/form/lettings/questions/county.rb +++ b/app/models/form/lettings/questions/county.rb @@ -5,6 +5,7 @@ class Form::Lettings::Questions::County < ::Form::Question @header = "County (optional)" @type = "text" @plain_label = true + @do_not_clear = true end def hidden_in_check_answers?(_log = nil, _current_user = nil) diff --git a/app/models/form/lettings/questions/la.rb b/app/models/form/lettings/questions/la.rb index 3cafda054..8c4ebade0 100644 --- a/app/models/form/lettings/questions/la.rb +++ b/app/models/form/lettings/questions/la.rb @@ -8,6 +8,7 @@ class Form::Lettings::Questions::La < ::Form::Question @check_answers_card_number = 0 @hint_text = "" @question_number = 13 + @do_not_clear = true end def answer_options diff --git a/app/models/form/lettings/questions/location_id.rb b/app/models/form/lettings/questions/location_id.rb index 94196534f..ab852cb31 100644 --- a/app/models/form/lettings/questions/location_id.rb +++ b/app/models/form/lettings/questions/location_id.rb @@ -1,6 +1,7 @@ class Form::Lettings::Questions::LocationId < ::Form::Question - def initialize(_id, hsh, page) - super("location_id", hsh, page) + def initialize(id, hsh, page) + super + @id = "location_id" @check_answer_label = "Location" @header = header_text @type = "radio" @@ -11,6 +12,7 @@ class Form::Lettings::Questions::LocationId < ::Form::Question }, } @question_number = 10 + @do_not_clear = true end def answer_options diff --git a/app/models/form/lettings/questions/postcode_for_full_address.rb b/app/models/form/lettings/questions/postcode_for_full_address.rb index 015abc2e8..9ac90b7d8 100644 --- a/app/models/form/lettings/questions/postcode_for_full_address.rb +++ b/app/models/form/lettings/questions/postcode_for_full_address.rb @@ -17,6 +17,7 @@ class Form::Lettings::Questions::PostcodeForFullAddress < ::Form::Question }, } @plain_label = true + @do_not_clear = true end def hidden_in_check_answers?(_log = nil, _current_user = nil) diff --git a/app/models/form/lettings/questions/postcode_full.rb b/app/models/form/lettings/questions/postcode_full.rb index 1f0a25c49..b3b5f6f21 100644 --- a/app/models/form/lettings/questions/postcode_full.rb +++ b/app/models/form/lettings/questions/postcode_full.rb @@ -10,5 +10,6 @@ class Form::Lettings::Questions::PostcodeFull < ::Form::Question @check_answers_card_number = 0 @hint_text = "" @inferred_answers = { "la" => { "is_la_inferred" => true } } + @do_not_clear = true end end diff --git a/app/models/form/lettings/questions/postcode_known.rb b/app/models/form/lettings/questions/postcode_known.rb index 6af30bb19..649c30098 100644 --- a/app/models/form/lettings/questions/postcode_known.rb +++ b/app/models/form/lettings/questions/postcode_known.rb @@ -8,6 +8,7 @@ class Form::Lettings::Questions::PostcodeKnown < ::Form::Question @check_answers_card_number = 0 @hint_text = "" @answer_options = ANSWER_OPTIONS + @do_not_clear = true @conditional_for = { "postcode_full" => [1] } @hidden_in_check_answers = { "depends_on" => [{ "postcode_known" => 0 }, { "postcode_known" => 1 }] } end diff --git a/app/models/form/lettings/questions/ppcodenk.rb b/app/models/form/lettings/questions/ppcodenk.rb index 33b03d959..3edc11cc6 100644 --- a/app/models/form/lettings/questions/ppcodenk.rb +++ b/app/models/form/lettings/questions/ppcodenk.rb @@ -11,6 +11,7 @@ class Form::Lettings::Questions::Ppcodenk < ::Form::Question @conditional_for = { "ppostcode_full" => [1] } @hidden_in_check_answers = { "depends_on" => [{ "ppcodenk" => 0 }, { "ppcodenk" => 1 }] } @question_number = 80 + @do_not_clear = true end ANSWER_OPTIONS = { "1" => { "value" => "Yes" }, "0" => { "value" => "No" } }.freeze diff --git a/app/models/form/lettings/questions/ppostcode_full.rb b/app/models/form/lettings/questions/ppostcode_full.rb index 0432d1b5b..14aa1ece4 100644 --- a/app/models/form/lettings/questions/ppostcode_full.rb +++ b/app/models/form/lettings/questions/ppostcode_full.rb @@ -11,5 +11,6 @@ class Form::Lettings::Questions::PpostcodeFull < ::Form::Question @hint_text = "" @inferred_answers = { "prevloc" => { "is_previous_la_inferred" => true } } @question_number = 80 + @do_not_clear = true end end diff --git a/app/models/form/lettings/questions/previous_la_known.rb b/app/models/form/lettings/questions/previous_la_known.rb index a9ff11e55..e93e52ea1 100644 --- a/app/models/form/lettings/questions/previous_la_known.rb +++ b/app/models/form/lettings/questions/previous_la_known.rb @@ -11,6 +11,7 @@ class Form::Lettings::Questions::PreviousLaKnown < ::Form::Question @conditional_for = { "prevloc" => [1] } @hidden_in_check_answers = { "depends_on" => [{ "previous_la_known" => 0 }, { "previous_la_known" => 1 }] } @question_number = 81 + @do_not_clear = true end ANSWER_OPTIONS = { "1" => { "value" => "Yes" }, "0" => { "value" => "No" } }.freeze diff --git a/app/models/form/lettings/questions/prevloc.rb b/app/models/form/lettings/questions/prevloc.rb index 229af2c18..75e1411dc 100644 --- a/app/models/form/lettings/questions/prevloc.rb +++ b/app/models/form/lettings/questions/prevloc.rb @@ -9,6 +9,7 @@ class Form::Lettings::Questions::Prevloc < ::Form::Question @check_answers_card_number = 0 @hint_text = "Select ‘Northern Ireland’, ‘Scotland’, ‘Wales’ or ‘Outside the UK’ if the household’s last settled home was outside England." @question_number = 81 + @do_not_clear = true end def answer_options diff --git a/app/models/form/lettings/questions/town_or_city.rb b/app/models/form/lettings/questions/town_or_city.rb index f1eac8dff..5f0f38491 100644 --- a/app/models/form/lettings/questions/town_or_city.rb +++ b/app/models/form/lettings/questions/town_or_city.rb @@ -5,6 +5,7 @@ class Form::Lettings::Questions::TownOrCity < ::Form::Question @header = "Town or city" @type = "text" @plain_label = true + @do_not_clear = true end def hidden_in_check_answers?(_log = nil, _current_user = nil) diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 8e8c26739..151e88506 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -1,5 +1,5 @@ class Form::Question - attr_accessor :id, :header, :hint_text, :description, :questions, + attr_accessor :id, :header, :hint_text, :description, :questions, :do_not_clear, :type, :min, :max, :step, :width, :fields_to_add, :result_field, :conditional_for, :readonly, :answer_options, :page, :check_answer_label, :inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value, @@ -42,6 +42,7 @@ class Form::Question @unresolved_hint_text = hsh["unresolved_hint_text"] @question_number = hsh["question_number"] @plain_label = hsh["plain_label"] + @do_not_clear = hsh["do_not_clear"] end end diff --git a/app/models/form/sales/pages/extra_borrowing_value_check.rb b/app/models/form/sales/pages/extra_borrowing_value_check.rb index 18f975b8d..5fff74db2 100644 --- a/app/models/form/sales/pages/extra_borrowing_value_check.rb +++ b/app/models/form/sales/pages/extra_borrowing_value_check.rb @@ -9,8 +9,7 @@ class Form::Sales::Pages::ExtraBorrowingValueCheck < Form::Page @title_text = { "translation" => "soft_validations.extra_borrowing.title", } - @informative_text = { - } + @informative_text = {} end def questions diff --git a/app/models/form/sales/questions/address_line1.rb b/app/models/form/sales/questions/address_line1.rb index a95051116..d0077fb29 100644 --- a/app/models/form/sales/questions/address_line1.rb +++ b/app/models/form/sales/questions/address_line1.rb @@ -7,6 +7,7 @@ class Form::Sales::Questions::AddressLine1 < ::Form::Question @type = "text" @plain_label = true @check_answer_label = "Q15 - Address" + @do_not_clear = true end def answer_label(log, _current_user = nil) diff --git a/app/models/form/sales/questions/address_line2.rb b/app/models/form/sales/questions/address_line2.rb index 0b4ff661c..80ba4f92d 100644 --- a/app/models/form/sales/questions/address_line2.rb +++ b/app/models/form/sales/questions/address_line2.rb @@ -5,6 +5,7 @@ class Form::Sales::Questions::AddressLine2 < ::Form::Question @header = "Address line 2 (optional)" @type = "text" @plain_label = true + @do_not_clear = true end def hidden_in_check_answers?(_log = nil, _current_user = nil) diff --git a/app/models/form/sales/questions/county.rb b/app/models/form/sales/questions/county.rb index 080ac809f..c27f9773b 100644 --- a/app/models/form/sales/questions/county.rb +++ b/app/models/form/sales/questions/county.rb @@ -5,6 +5,7 @@ class Form::Sales::Questions::County < ::Form::Question @header = "County (optional)" @type = "text" @plain_label = true + @do_not_clear = true end def hidden_in_check_answers?(_log = nil, _current_user = nil) diff --git a/app/models/form/sales/questions/postcode.rb b/app/models/form/sales/questions/postcode.rb index 0f72a9585..0e9ac9303 100644 --- a/app/models/form/sales/questions/postcode.rb +++ b/app/models/form/sales/questions/postcode.rb @@ -17,5 +17,6 @@ class Form::Sales::Questions::Postcode < ::Form::Question "is_la_inferred" => true, }, } + @do_not_clear = true end end diff --git a/app/models/form/sales/questions/postcode_for_full_address.rb b/app/models/form/sales/questions/postcode_for_full_address.rb index a1e6f8633..33aef09d6 100644 --- a/app/models/form/sales/questions/postcode_for_full_address.rb +++ b/app/models/form/sales/questions/postcode_for_full_address.rb @@ -17,6 +17,7 @@ class Form::Sales::Questions::PostcodeForFullAddress < ::Form::Question }, } @plain_label = true + @do_not_clear = true end def hidden_in_check_answers?(_log = nil, _current_user = nil) diff --git a/app/models/form/sales/questions/previous_la_known.rb b/app/models/form/sales/questions/previous_la_known.rb index 1a9a646f3..60e3052a4 100644 --- a/app/models/form/sales/questions/previous_la_known.rb +++ b/app/models/form/sales/questions/previous_la_known.rb @@ -21,6 +21,7 @@ class Form::Sales::Questions::PreviousLaKnown < ::Form::Question "prevloc" => [1], } @question_number = 58 + @do_not_clear = true end ANSWER_OPTIONS = { diff --git a/app/models/form/sales/questions/previous_postcode.rb b/app/models/form/sales/questions/previous_postcode.rb index 568ba66ea..4bac3e867 100644 --- a/app/models/form/sales/questions/previous_postcode.rb +++ b/app/models/form/sales/questions/previous_postcode.rb @@ -18,5 +18,6 @@ class Form::Sales::Questions::PreviousPostcode < ::Form::Question }, } @question_number = 57 + @do_not_clear = true end end diff --git a/app/models/form/sales/questions/previous_postcode_known.rb b/app/models/form/sales/questions/previous_postcode_known.rb index e83fda8d3..0aee9cebf 100644 --- a/app/models/form/sales/questions/previous_postcode_known.rb +++ b/app/models/form/sales/questions/previous_postcode_known.rb @@ -21,6 +21,7 @@ class Form::Sales::Questions::PreviousPostcodeKnown < ::Form::Question ], } @question_number = 57 + @do_not_clear = true end ANSWER_OPTIONS = { diff --git a/app/models/form/sales/questions/prevloc.rb b/app/models/form/sales/questions/prevloc.rb index 75bb50e81..4bd034bf4 100644 --- a/app/models/form/sales/questions/prevloc.rb +++ b/app/models/form/sales/questions/prevloc.rb @@ -12,6 +12,7 @@ class Form::Sales::Questions::Prevloc < ::Form::Question "value" => "Not known", }] @question_number = 58 + @do_not_clear = true end def answer_options diff --git a/app/models/form/sales/questions/property_local_authority.rb b/app/models/form/sales/questions/property_local_authority.rb index 04dbed347..8716dc130 100644 --- a/app/models/form/sales/questions/property_local_authority.rb +++ b/app/models/form/sales/questions/property_local_authority.rb @@ -6,6 +6,7 @@ class Form::Sales::Questions::PropertyLocalAuthority < ::Form::Question @header = "What is the property’s local authority?" @type = "select" @question_number = 16 + @do_not_clear = true end def answer_options diff --git a/app/models/form/sales/questions/town_or_city.rb b/app/models/form/sales/questions/town_or_city.rb index 9dde3aeb8..635ccd90a 100644 --- a/app/models/form/sales/questions/town_or_city.rb +++ b/app/models/form/sales/questions/town_or_city.rb @@ -5,6 +5,7 @@ class Form::Sales::Questions::TownOrCity < ::Form::Question @header = "Town or city" @type = "text" @plain_label = true + @do_not_clear = true end def hidden_in_check_answers?(_log = nil, _current_user = nil) diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 741195f01..167396196 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -24,6 +24,7 @@ "header": "Do you know the property’s postcode?", "hint_text": "", "type": "radio", + "do_not_clear": true, "answer_options": { "1": { "value": "Yes" @@ -54,6 +55,7 @@ "hint_text": "", "type": "text", "width": 5, + "do_not_clear": true, "inferred_answers": { "la": { "is_la_inferred": true @@ -82,6 +84,7 @@ "header": "What is the local authority of the property?", "hint_text": "", "type": "select", + "do_not_clear": true, "answer_options": { "": "Select an option", "E07000223": "Adur", @@ -6482,6 +6485,7 @@ "header": "Do you know the postcode of the household’s last settled accommodation?", "hint_text": "This is also known as the household’s ‘last settled home’.", "type": "radio", + "do_not_clear": true, "answer_options": { "1": { "value": "Yes" @@ -6512,6 +6516,7 @@ "hint_text": "", "type": "text", "width": 5, + "do_not_clear": true, "inferred_answers": { "prevloc": { "is_previous_la_inferred": true @@ -6535,6 +6540,7 @@ "header": "Do you know the local authority of the household’s last settled accommodation?", "hint_text": "This is also known as the household’s ‘last settled home’.", "type": "radio", + "do_not_clear": true, "hidden_in_check_answers": { "depends_on": [ { @@ -6564,6 +6570,7 @@ "header": "Select a local authority", "hint_text": "Select ‘Northern Ireland’, ‘Scotland’, ‘Wales’ or ‘Outside the UK’ if the household’s last settled home was outside England.", "type": "select", + "do_not_clear": true, "answer_options": { "": "Select an option", "S12000033": "Aberdeen City", diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json index 9b5aa6bb8..9b30a73fb 100644 --- a/config/forms/2022_2023.json +++ b/config/forms/2022_2023.json @@ -24,6 +24,7 @@ "header": "Do you know the property’s postcode?", "hint_text": "", "type": "radio", + "do_not_clear": true, "answer_options": { "1": { "value": "Yes" @@ -54,6 +55,7 @@ "hint_text": "", "type": "text", "width": 5, + "do_not_clear": true, "inferred_answers": { "la": { "is_la_inferred": true @@ -82,6 +84,7 @@ "header": "What is the local authority of the property?", "hint_text": "", "type": "select", + "do_not_clear": true, "answer_options": { "": "Select an option", "E07000223": "Adur", @@ -6435,6 +6438,7 @@ "header": "Do you know the postcode of the household’s last settled accommodation?", "hint_text": "This is also known as the household’s ‘last settled home’.", "type": "radio", + "do_not_clear": true, "answer_options": { "1": { "value": "Yes" @@ -6465,6 +6469,7 @@ "hint_text": "", "type": "text", "width": 5, + "do_not_clear": true, "inferred_answers": { "prevloc": { "is_previous_la_inferred": true @@ -6488,6 +6493,7 @@ "header": "Do you know the local authority of the household’s last settled accommodation?", "hint_text": "This is also known as the household’s ‘last settled home’.", "type": "radio", + "do_not_clear": true, "hidden_in_check_answers": { "depends_on": [ { @@ -6517,6 +6523,7 @@ "header": "Select a local authority", "hint_text": "Select ‘Northern Ireland’, ‘Scotland’, ‘Wales’ or ‘Outside the UK’ if the household’s last settled home was outside England.", "type": "select", + "do_not_clear": true, "answer_options": { "": "Select an option", "S12000033": "Aberdeen City", diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 97999d8a3..b007189be 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -411,6 +411,7 @@ "hint_text": "Type ahead to filter the options", "type": "select", "check_answer_label": "Accessible Select", + "do_not_clear": true, "answer_options": { "": "Select an option", "E07000223": "Adur", @@ -473,6 +474,7 @@ "hint_text": "Type ahead to filter the options", "type": "select", "check_answer_label": "Accessible Select", + "do_not_clear": true, "answer_options": { "": "Select an option", "E07000223": "Adur", @@ -500,6 +502,7 @@ "header": "Do you know the property’s postcode?", "hint_text": "", "type": "radio", + "do_not_clear": true, "answer_options": { "1": { "value": "Yes" @@ -521,6 +524,7 @@ "hint_text": "", "type": "text", "width": 5, + "do_not_clear": true, "inferred_answers": { "la": { "is_la_inferred": true @@ -544,6 +548,7 @@ "header": "Do you know what local authority the property is located in?", "hint_text": "", "type": "radio", + "do_not_clear": true, "answer_options": { "0": { "value": "No" @@ -1151,6 +1156,7 @@ "header": "Postcode for the previous accommodation", "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", "type": "text", + "do_not_clear": true, "width": 5 } }