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| %> - -