Browse Source

Merge d63affa550 into 97a758ebe0

pull/3158/merge
Samuel Young 5 days ago committed by GitHub
parent
commit
71c9642262
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      app/helpers/collection_time_helper.rb
  2. 9
      app/helpers/form_page_helper.rb
  3. 13
      app/models/form/lettings/questions/tenancy_start_date.rb
  4. 5
      app/models/form/question.rb
  5. 2
      app/views/form/_date_question.html.erb
  6. 3
      config/locales/forms/2026/lettings/setup.en.yml

9
app/helpers/collection_time_helper.rb

@ -16,10 +16,13 @@ module CollectionTimeHelper
Time.zone.local(collection_start_year_for_date(date), 4, 1)
end
def date_mid_collection_year_formatted(date)
def date_mid_collection_year(date)
relevant_year = date.nil? ? current_collection_start_year : collection_start_year_for_date(date)
example_date = Date.new(relevant_year, 9, 13)
example_date.to_formatted_s(:govuk_date_number_month)
Date.new(relevant_year, 9, 13)
end
def date_mid_collection_year_formatted(date)
date_mid_collection_year(date).to_formatted_s(:govuk_date_number_month)
end
def current_collection_start_date

9
app/helpers/form_page_helper.rb

@ -1,4 +1,6 @@
module FormPageHelper
include CollectionTimeHelper
def action_href(log, page_id, referrer = "check_answers")
send("#{log.log_type}_#{page_id}_path", log, referrer:)
end
@ -46,4 +48,11 @@ module FormPageHelper
page.skip_href(log) || send(log.form.next_page_redirect_path(page, log, current_user, ignore_answered: true), log)
end
end
def date_hint(question, log)
[
question.hint_text.presence,
question.date_example_override(log) || "For example, #{date_mid_collection_year_formatted(log.startdate).tr(' ', '/')}",
].compact.join("<br><br>").html_safe
end
end

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

@ -1,4 +1,6 @@
class Form::Lettings::Questions::TenancyStartDate < ::Form::Question
include CollectionTimeHelper
def initialize(id, hsh, page)
super
@id = "startdate"
@ -7,5 +9,16 @@ class Form::Lettings::Questions::TenancyStartDate < ::Form::Question
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] if form.start_date.present?
end
def date_example_override(log)
return unless form.start_year_2026_or_later?
example_date =
[date_mid_collection_year(log.startdate), Time.zone.today + 7]
.min
.to_formatted_s(:govuk_date_number_month)
.tr(" ", "/")
I18n.t("forms.#{form.start_date.year}.#{copy_key}.example", default: "", example_date:)
end
QUESTION_NUMBER_FROM_YEAR = { 2023 => 5, 2024 => 7 }.freeze
end

5
app/models/form/question.rb

@ -299,6 +299,11 @@ class Form::Question
answer_options.keys.reject { |x| x.match(/divider/) }
end
# used by date questions that need bespoke formatting for the example date
def date_example_override(_log)
nil
end
private
def selected_answer_option_is_derived?(log)

2
app/views/form/_date_question.html.erb

@ -6,7 +6,7 @@
question_id: question.id,
legend: { text: legend[:text], size: legend[:size], caption: caption(caption_text, page_header, conditional) },
resource_type: @log.log_type,
hint: (question.hint_text.blank? ? "" : (question.hint_text.html_safe + "</br></br>".html_safe)) + "For example, #{date_mid_collection_year_formatted(@log.startdate).tr(' ', '/')}",
hint: date_hint(question, @log),
f:,
} %>

3
config/locales/forms/2026/lettings/setup.en.yml

@ -63,7 +63,8 @@ en:
page_header: ""
check_answer_label: "Tenancy start date"
check_answer_prompt: ""
hint_text: ""
hint_text: "The tenancy start date can be up to 14 days from today. If your tenancy starts more than 14 days into the future, please wait until you are within 14 days of the start date before submitting your log. <br><br>If you’re answering this question on 1 April, you can enter a tenancy start date up to and including 15 April."
example: "Enter the date in the format DD/MM/YYYY, for example %{example_date}."
question_text: "What is the tenancy start date?"
rent_type:

Loading…
Cancel
Save