public
Created

Workaround for Issue #2059 in Symfony 2.0

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?php
namespace Rousseau\PaymentBundle\Form\DataTransformer;
 
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Doctrine\Common\Persistence\ObjectManager;
 
/*
Usage:
$builder->add(
$builder->create('amount')->appendClientTransformer(new CommaToDotTransformer())
);
*/
 
/* Allow using comma, when only dot is accepted by locale as decimal separator */
class CommaToDotTransformer implements DataTransformerInterface
{
public function transform($number)
{
return $number;
}
 
public function reverseTransform($input)
{
return str_replace(',', '.', $input);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.