mbajorek mbajorek - 2 years ago 308
PHP Question

Symfony forms, error bubbling

I have a problem with forms' error bubbling.
One field in my form is defined like this:

'required' => true,
'error_bubbling' => false,

I would like to add a validator like this to this field:

* @Assert\True(message = "Bad title.")
public function getTitleCorrect()
/* ... */
return false;

It works ok, but the error message shows up on top of the form, not in the field row.

In the Twig template this error message is rendered by
as a global error. When I use
, it does not print my error.

What can I do to change the assignment of the error?

Answer Source

Messages are attached to a field only when validator is attached to corresponding property. Your validator is attached to a method of the class so error is indeed global.

You should to something like that:

use ...\TitleValidator as AssertTitleValid;

class MyEntity
     * @AssertTitleValid
    private $title;

And create your own TitleValidator class.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download