From 273cdc083751945c7e1ee4a59b2004d0875e037c Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 29 Mar 2023 10:53:06 +0100 Subject: [PATCH] feat: add webform validation --- app/models/validations/household_validations.rb | 9 +++++++++ config/locales/en.yml | 3 +++ 2 files changed, 12 insertions(+) diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index e56a16783..8f28bff74 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -112,6 +112,15 @@ module Validations::HouseholdValidations end end + def validate_layear(record) + return unless record.layear && record.renewal + + if record.is_renewal? && record.layear == 1 + record.errors.add :layear, I18n.t("validations.household.renewal_just_moved_to_area.layear") + record.errors.add :renewal, I18n.t("validations.household.renewal_just_moved_to_area.renewal") + end + end + private def household_no_illness?(record) diff --git a/config/locales/en.yml b/config/locales/en.yml index 45cbde94a..1c7dbaa5a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -414,6 +414,9 @@ en: reasonpref: not_homeless: "Answer cannot be ‘no’ as the tenant was homeless or about to lose their home" previous_la_known: "Enter name of local authority" + renewal_just_moved_to_area: + layear: 'For a renewal, you cannot select "just moved to local authority area"' + renewal: 'This cannot be a renewal as you told us the household "just moved to local authority area"' gender: retired_male: "Answer cannot be ‘male’ as tenant is under 65 and retired" retired_female: "Answer cannot be ‘female’ as tenant is under 60 and retired"