add validation on decimal max 3 digits after coma

This commit is contained in:
Lisa Durand 2024-03-18 18:10:26 +01:00
parent a60bc5d630
commit a3ab6dd257
5 changed files with 25 additions and 2 deletions

View file

@ -1,6 +1,14 @@
class Champs::DecimalNumberChamp < Champ
before_validation :format_value
validates :value, numericality: {
validates :value, format: {
with: /\A-?[0-9]+([\.,][0-9]{1,3})?\z/,
allow_nil: true,
allow_blank: true,
message: -> (object, _data) {
# i18n-tasks-use t('errors.messages.not_a_float')
"« #{object.libelle} » " + object.errors.generate_message(:value, :not_a_float)
}
}, numericality: {
allow_nil: true,
allow_blank: true,
message: -> (object, _data) {