Symfony 2 Number Field with validation constraint not working

1.2k views Asked by At

I try to insert a string in number field to benchthe validation, but it is not working

/**
     * @Assert\Length(max = "16")
     * @Assert\NotBlank(groups={"specific"},message="Le montant doit etre renseigné")
     * @Assert\Type(type="numeric", message="La valeur {{ value }} n'est pas un nombre.")
     *
     * @var decimal $amount
     *
     * @ORM\Column(name="amount", type="decimal", length=16, nullable=true)
     */
    private $amount;

Each time submit the forme i have a postgresql error :

SQLSTATE[22P02]: Invalid text representation

I m expecting the folowing message instead

"The value is xxx not a number"

I am using symfony 2.4 with INTL extension installed on serveur with php 5.5

1

There are 1 answers

0
Chopchop On BEST ANSWER

i specify the validation group to take it in account

/**
     * @Assert\Length(max = "9")
     * @Assert\Type(groups={"avantage"},type="numeric", message="La valeur {{ value }} n'est pas un nombre.")
     * @Assert\NotBlank(groups={"avantage"},message="Le montant doit etre renseigné")
     *
     * @var decimal $amount
     *
     * @ORM\Column(name="amount", type="decimal", length=16, nullable=true)
     */
    private $amount;