Browse Source

Add functionality

CLDC-4139-tenancy-type-other-free-text-validation
oscar-richardson-softwire 7 days ago
parent
commit
9103e5d5ad
  1. 24
      app/models/form/lettings/pages/tenancyother_value_check.rb
  2. 13
      app/models/form/lettings/questions/tenancyother_value_check.rb
  3. 1
      app/models/form/lettings/subsections/tenancy_information.rb
  4. 10
      app/models/validations/soft_validations.rb
  5. 10
      config/locales/forms/2026/lettings/soft_validations.en.yml
  6. 5
      db/migrate/20260212091506_add_tenancyother_value_check_to_lettings_logs.rb
  7. 3
      db/schema.rb

24
app/models/form/lettings/pages/tenancyother_value_check.rb

@ -0,0 +1,24 @@
class Form::Lettings::Pages::TenancyotherValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "tenancyother_value_check"
@copy_key = "lettings.soft_validations.tenancyother_value_check"
@depends_on = [{ "tenancyother_might_be_introductory_or_starter_period?" => true }]
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [{ "key" => "tenancyother", "i18n_template" => "tenancyother" }],
}
@informative_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text",
"arguments" => [],
}
end
def questions
@questions ||= [Form::Lettings::Questions::TenancyotherValueCheck.new(nil, nil, self)]
end
def interruption_screen_question_ids
%w[tenancy tenancyother]
end
end

13
app/models/form/lettings/questions/tenancyother_value_check.rb

@ -0,0 +1,13 @@
class Form::Lettings::Questions::TenancyotherValueCheck < ::Form::Question
def initialize(id, hsh, page)
super
@id = "tenancyother_value_check"
@copy_key = "lettings.soft_validations.tenancyother_value_check"
@type = "interruption_screen"
@check_answers_card_number = 0
@answer_options = ANSWER_OPTIONS
@hidden_in_check_answers = { "depends_on" => [{ "tenancyother_value_check" => 0 }, { "tenancyother_value_check" => 1 }] }
end
ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze
end

1
app/models/form/lettings/subsections/tenancy_information.rb

@ -13,6 +13,7 @@ class Form::Lettings::Subsections::TenancyInformation < ::Form::Subsection
Form::Lettings::Pages::TenancyType.new(nil, nil, self),
Form::Lettings::Pages::StarterTenancyType.new(nil, nil, self),
Form::Lettings::Pages::TenancyLength.new(nil, nil, self),
(Form::Lettings::Pages::TenancyotherValueCheck.new(nil, nil, self) if form.start_year_2026_or_later?),
Form::Lettings::Pages::TenancyLengthAffordableRent.new(nil, nil, self),
Form::Lettings::Pages::TenancyLengthIntermediateRent.new(nil, nil, self),
(Form::Lettings::Pages::TenancyLengthPeriodic.new(nil, nil, self) if form.start_year_2024_or_later?),

10
app/models/validations/soft_validations.rb

@ -208,6 +208,16 @@ module Validations::SoftValidations
PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY_REGEX.match?(reasonother)
end
PHRASES_LIKELY_TO_INDICATE_INTRODUCTORY_OR_STARTER_PERIOD = %w[introductory intro starter].freeze
PHRASES_LIKELY_TO_INDICATE_INTRODUCTORY_OR_STARTER_PERIOD_REGEX = Regexp.union(
PHRASES_LIKELY_TO_INDICATE_INTRODUCTORY_OR_STARTER_PERIOD.map { |phrase| Regexp.new("\\b[^[:alpha]]*#{phrase}[^[:alpha:]]*\\b", Regexp::IGNORECASE) },
)
def tenancyother_might_be_introductory_or_starter_period?
PHRASES_LIKELY_TO_INDICATE_INTRODUCTORY_OR_STARTER_PERIOD_REGEX.match?(tenancyother)
end
def multiple_partners?
return unless hhmemb

10
config/locales/forms/2026/lettings/soft_validations.en.yml

@ -57,6 +57,16 @@ en:
title_text: "You told us that the tenant’s main reason for leaving their last settled home was %{reasonother}."
informative_text: "The reason you have entered looks very similar to one of the existing response categories. Please check the categories and select the appropriate one. If the existing categories are not suitable, please confirm here to move onto the next question."
tenancyother_value_check:
page_header: ""
check_answer_label: "Tenancy other confirmation"
check_answer_prompt: "Confirm tenancy type"
hint_text: ""
question_text: ""
title_text: "You told us that the type of tenancy was %{tenancyother}."
informative_text: "Give the type of tenancy that the tenants rolls onto after any introductory or starter period."
referral_value_check:
page_header: ""
check_answer_label: "Referral confirmation"

5
db/migrate/20260212091506_add_tenancyother_value_check_to_lettings_logs.rb

@ -0,0 +1,5 @@
class AddTenancyotherValueCheckToLettingsLogs < ActiveRecord::Migration[7.0]
def change
add_column :lettings_logs, :tenancyother_value_check, :integer
end
end

3
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.2].define(version: 2026_01_28_121417) do
ActiveRecord::Schema[7.2].define(version: 2026_02_12_091506) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -384,6 +384,7 @@ ActiveRecord::Schema[7.2].define(version: 2026_01_28_121417) do
t.string "sexrab6"
t.string "sexrab7"
t.string "sexrab8"
t.integer "tenancyother_value_check"
t.index ["assigned_to_id"], name: "index_lettings_logs_on_assigned_to_id"
t.index ["bulk_upload_id"], name: "index_lettings_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id"

Loading…
Cancel
Save