I’m continuing my study of Symfony2 and new “problems” are found!
Let me describe the problem.
I have a class that construct a form on a Doctrine Entity. It is identical to the registration form example described at this page of the official docs. The only difference is that I use Doctrine instead of MongoDB.
Now, I added the following field into the User class
/**
* @Assert\Type(type="integer", message="Not an integer.")
* @ORM\Column(type="smallint", name="num")
*
* @var Smallint $num
*
*/
protected $num;
Then, I updated function buildForm in class UserType by adding the following lines:
public function buildForm(FormBuilder $builder, array $options)
{
...
$builder->add('num', 'integer', array(
'label' => 'Insert a number',
));
}
Here is the problem. Notwithstanding that I provide a custom message through Annotation, a wrong input for the field num (i.e. a string value) returns the following error code: “This value is not valid” instead of “Not an integer“.
Any idea about this missed interpretation of the customized error message?
Try adding
In
buildFormmethod.