Created
August 19, 2012 13:41
-
-
Save fain182/3394880 to your computer and use it in GitHub Desktop.
Workaround for Issue #2059 in Symfony 2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
From symfony 2.1, appendClientTransformer is replaced by addViewTransformer
->add(
$builder
->create('your_field', 'text')
->addViewTransformer(new CommaToDotTransformer())
)
Very thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Im trying to implement this part of your code
My form
And the transformer class
This is my error
FatalErrorException: Error: Call to undefined method Symfony\Component\Form\FormBuilder::appendClientTransformer() in C:\Dropbox\Apache Xampp\evaluacion_daci\src\daci\contratosBundle\Form\Type\contratosType.php line 32
Any idea what is going on