Merge pull request #9694 from demarches-simplifiees/fix-number-type-condition-bug

ETQ admin je peux conditionner / router avec un champ de type nombre décimal
This commit is contained in:
Eric Leroy-Terquem 2023-11-15 09:04:07 +00:00 committed by GitHub
commit f1954c1546
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,9 +48,10 @@ class ConditionForm
return empty if value.blank?
if left_type == :number
# in this special case, we try to cast as Integer
# in this special case, we try to cast as Float, then Integer
# but it can still be a previous string value or a mistap
number = Integer(value) rescue nil
number = parse_to_number(value)
return constant(number) if number
end
@ -62,4 +63,11 @@ class ConditionForm
# if anything else, save it as a constant of string
constant(value)
end
def parse_to_number(str)
float = Float(str)
float % 1 == 0 ? float.to_i : float
rescue ArgumentError
nil
end
end