diff --git a/app/models/champs/decimal_number_champ.rb b/app/models/champs/decimal_number_champ.rb index 2669dbc9b39..7a05abb33ff 100644 --- a/app/models/champs/decimal_number_champ.rb +++ b/app/models/champs/decimal_number_champ.rb @@ -23,11 +23,20 @@ class Champs::DecimalNumberChamp < Champ validates :value, numericality: { allow_nil: true, - allow_blank: true, - message: -> (object, _data) { - "« #{object.libelle} » " + object.errors.generate_message(:value, :not_a_number) - } + allow_blank: true } + validate :min_max_validation + + def min_max_validation + return if value.blank? + + if type_de_champ.min.present? && value.to_i < type_de_champ.min.to_i + errors.add(:value, :greater_than_or_equal_to, value: value, count: type_de_champ.min.to_i) + end + if type_de_champ.max.present? && value.to_i > type_de_champ.max.to_i + errors.add(:value, :less_than_or_equal_to, value: value, count: type_de_champ.max.to_i) + end + end def for_export processed_value diff --git a/app/models/champs/integer_number_champ.rb b/app/models/champs/integer_number_champ.rb index 7e123a646a0..94faa33120e 100644 --- a/app/models/champs/integer_number_champ.rb +++ b/app/models/champs/integer_number_champ.rb @@ -24,12 +24,20 @@ class Champs::IntegerNumberChamp < Champ validates :value, numericality: { only_integer: true, allow_nil: true, - allow_blank: true, - message: -> (object, _data) { - # i18n-tasks-use t('errors.messages.not_an_integer') - "« #{object.libelle} » " + object.errors.generate_message(:value, :not_an_integer) - } + allow_blank: true } + validate :min_max_validation + + def min_max_validation + return if value.blank? + + if type_de_champ.min.present? && value.to_i < type_de_champ.min.to_i + errors.add(:value, :greater_than_or_equal_to, value: value, count: type_de_champ.min.to_i) + end + if type_de_champ.max.present? && value.to_i > type_de_champ.max.to_i + errors.add(:value, :less_than_or_equal_to, value: value, count: type_de_champ.max.to_i) + end + end def for_export processed_value