From fcf0919d2ba7f7b568fe8c238caeead0a0095732 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 11 Nov 2022 16:04:27 +0000 Subject: [PATCH] feat: add general partially missing date input error --- app/controllers/schemes_controller.rb | 7 ++----- config/locales/en.yml | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 0b4e57113..c59a616a5 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -30,7 +30,7 @@ class SchemesController < ApplicationController deactivation_date_errors if @scheme.errors.present? @scheme.deactivation_date_type = params[:scheme][:deactivation_date_type] - # @scheme.deactivation_date = deactivation_date_errors + @scheme.deactivation_date = nil render "toggle_active", locals: { action: "deactivate" }, status: :unprocessable_entity else render "toggle_active_confirm", locals: { action: "deactivate", deactivation_date: } @@ -302,10 +302,7 @@ private collection_start_date = FormHandler.instance.current_collection_start_date if [day, month, year].any?(&:blank?) - { day:, month:, year: }.each do |period, value| - @scheme.errors.add(:deactivation_date, message: I18n.t("validations.scheme.deactivation_date.not_entered", period: period.to_s)) if value.blank? - end - # { 1 => year.to_i, 2 => month.to_i, 3 => day.to_i } + @scheme.errors.add(:deactivation_date, message: I18n.t("validations.scheme.deactivation_date.not_entered")) elsif !Date.valid_date?(year.to_i, month.to_i, day.to_i) @scheme.errors.add(:deactivation_date, message: I18n.t("validations.scheme.deactivation_date.invalid")) elsif !Date.new(year.to_i, month.to_i, day.to_i).between?(collection_start_date, Date.new(2200, 1, 1)) diff --git a/config/locales/en.yml b/config/locales/en.yml index 1d0a82ca9..927cb91b1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -314,7 +314,7 @@ en: scheme: deactivation_date: not_selected: "Select one of the options" - not_entered: "Enter a %{period}" + not_entered: "Enter a day, month and year" invalid: "Enter a valid date" out_of_range: "The date must be on or after the %{date}"