Merge pull request #10143 from demarches-simplifiees/float-too-many-decimal-ldu

ETQ admin, je veux que le champ nombre décimal ne prenne que 3 chiffres après la virgule
This commit is contained in:
Lisa Durand 2024-03-27 10:05:35 +00:00 committed by GitHub
commit 65b8f6881a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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) {