Skip to content

Instantly share code, notes, and snippets.

@fain182
Created August 19, 2012 13:41
Show Gist options
  • Save fain182/3394880 to your computer and use it in GitHub Desktop.
Save fain182/3394880 to your computer and use it in GitHub Desktop.
Workaround for Issue #2059 in Symfony 2.0
<?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);
}
}
@gaea44
Copy link

gaea44 commented Feb 20, 2015

From symfony 2.1, appendClientTransformer is replaced by addViewTransformer

->add(
    $builder
        ->create('your_field', 'text')
        ->addViewTransformer(new CommaToDotTransformer())
)

@ianitsky
Copy link

Very thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment