diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 2bc7428a1..b1db9064f 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -28,21 +28,27 @@ class SchemesController < ApplicationController flash[:notice] = "#{@scheme.service_name} has been deactivated" end redirect_to scheme_details_path(@scheme) - return elsif deactivation_date.present? if deactivation_date == "other" - @scheme.errors.add(:deactivation_date, message: "Enter a date") - render "toggle_active", locals: { action: "deactivate", deactivation_date: } + if params[:scheme]["deactivation_date(1i)"].blank? && params[:scheme]["deactivation_date(2i)"].blank? && params[:scheme]["deactivation_date(3i)"].blank? + @scheme.errors.add(:deactivation_date, message: "Enter a date") + elsif params[:scheme]["deactivation_date(3i)"].blank? + @scheme.errors.add(:deactivation_date, message: "Enter the day") + elsif params[:scheme]["deactivation_date(2i)"].blank? + @scheme.errors.add(:deactivation_date, message: "Enter the month") + elsif params[:scheme]["deactivation_date(1i)"].blank? + @scheme.errors.add(:deactivation_date, message: "Enter the year") + end + render "toggle_active", locals: { action: "deactivate", deactivation_date: }, status: :unprocessable_entity else render "toggle_active_confirm", locals: { action: "deactivate", deactivation_date: } end - return elsif params[:scheme] @scheme.errors.add(:deactivation_date, message: "Select one of the options") - render "toggle_active", locals: { action: "deactivate", deactivation_date: } - return + render "toggle_active", locals: { action: "deactivate", deactivation_date: }, status: :unprocessable_entity + else + render "toggle_active", locals: { action: "deactivate" } end - render "toggle_active", locals: { action: "deactivate" } end def new diff --git a/app/views/schemes/toggle_active.html.erb b/app/views/schemes/toggle_active.html.erb index dd3406d13..d06066363 100644 --- a/app/views/schemes/toggle_active.html.erb +++ b/app/views/schemes/toggle_active.html.erb @@ -6,16 +6,12 @@ <% end %> <%= form_with model: @scheme, url: scheme_deactivate_path(@scheme), method: "get", local: true do |f| %> - -

- <%= @scheme.service_name %> - <%= "When should this change apply?" %> -

<%= f.govuk_error_summary %> <%= f.govuk_radio_buttons_fieldset :deactivation_date, - legend: nil, + legend: { text: "When should this change apply?" }, + caption: { text: @scheme.service_name }, hint: { text: "If the date is before 1 April 2022, select ‘From the start of the current collection period’ because the previous period has now closed."} do %> <%= govuk_warning_text text: "It will not be possible to add logs with this scheme if their tenancy start date is on or after the date you enter. Any existing logs may be affected." %> <%= f.govuk_radio_button :deactivation_date, @@ -26,7 +22,7 @@ "other", label: { text: "For tenancies starting after a certain date" }, **basic_conditional_html_attributes({"deactivation_date" => ["other"]}, "scheme") do %> - <%= f.govuk_date_field :deactivation_date, + <%= f.govuk_date_field :deactivation_date_field, legend: { text: "Date", size: "m" }, hint: { text: "For example, 27 3 2008" }, width: 20 %>