Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a number field that accepts numbers with comma or period in symfony 2

I have an application with a decimal field like:

/**
 * @var decimal $amount
 *
 * @ORM\Column(name="amount", type="decimal", scale="2")
 */
private $amount;

I want that the form to accept numbers with a format like "3,4" or "3.4".

If I enter "3.4" the application save in the database "3.4", if I enter "3,4" the application saves in the database "34" (yes, without comma and without showing validation error!).

(This is a known symfony bug: https://github.com/symfony/symfony/issues/2059 )

So, how can i accept numbers with commas as well as decimal points?

(I already tried to substitute commas with dot in a DataTrasformer, but DataTransformer takes the number already normalized.)

like image 491
fain182 Avatar asked Aug 19 '12 11:08

fain182


1 Answers

I found a workaround using a DataTransformer with appendClientTransformer, here is the snippet: https://gist.github.com/3394880

like image 150
fain182 Avatar answered Sep 28 '22 02:09

fain182