I have a field with sets of validation rules:
/**
* @var integer
*
* @ORM\Column(name="options", type="integer")
* @Assert\NotBlank()
* @Assert\Min(limit = "1381", message = "Please provide number higher than 1381")
* @Assert\Regex(pattern = "/^\d{4}$/" , message = "Four digits are expected")
*/
private $options;
and it seems sometimes Symfony is checking every assertion(what is good) and render every error in view(what is not expected). After submitting a form with option=5 I got folowed error messages in view.
Options
- Please provide number higher than 1381
- Four digits are expected
but when I send option = null then only one error message is displayed.
Options
- This value should not be blank.
Is there a ‘switch’ which causes that only one error message is rendered in template? I would like to have only one error message per field in my forms.
====== edit ======
Solution I like by Bernhard Schussek
Patt thanks for pointing me there
One option is to modify the template/block for a form error block application wide (so that every one of your forms in a template will get the desired behaviour). Or override the form layout on a per template basis.
If you go and look at the default form layout that ships with the Symfony standard edition you can see on line 273 the
form_errorstwigblockis defined.You could override this block in a given template (as per the documentation), to only echo one element from the
errorsarray: