From 0dc5921495822f061fb1fa0ccd0bdd5e9fce187f Mon Sep 17 00:00:00 2001 From: Chris Preisinger Date: Tue, 17 Dec 2024 12:54:44 -0500 Subject: [PATCH] 296 Override default phase presence error for form --- app/models/evaluation_form.rb | 4 +++- config/locales/en.yml | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/evaluation_form.rb b/app/models/evaluation_form.rb index b0baf9b9..afdaeebd 100644 --- a/app/models/evaluation_form.rb +++ b/app/models/evaluation_form.rb @@ -17,7 +17,7 @@ # class EvaluationForm < ApplicationRecord belongs_to :challenge - belongs_to :phase + belongs_to :phase, optional: true # Disables default must exist error message has_many :evaluation_criteria, lambda { order(:created_at) }, class_name: 'EvaluationCriterion', dependent: :destroy, inverse_of: :evaluation_form @@ -35,6 +35,8 @@ class EvaluationForm < ApplicationRecord validates :scale_type, presence: true validates :closing_date, presence: true + # Adds custom error message for phase presence failure instead of default from above + validates :phase, presence: { message: I18n.t("evaluation_form.phase.presence_error") } validates :phase_id, uniqueness: true validate :criteria_weights_must_sum_to_one_hundred diff --git a/config/locales/en.yml b/config/locales/en.yml index 8800f0ba..1339adc4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -36,6 +36,9 @@ en: login_error: "There was an issue with logging in. Please try again." please_try_again: "Please try again." session_expired_alert: "Your session has expired. Please log in again." + evaluation_form: + phase: + presence_error: "can't be blank" evaluation_criteria: duplicate_title_error: "must be unique within criteria" must_sum_to_100_error: "must sum to 100 with other criteria"