I have created custom validator that validates object comparing its fields (it uses EntityManager to validate fields).
When the object is invalid MyValidator adds error message to Form object, because validator is associated to Entity not Field.
/**
* @StrictAssert\MyValidator
*/
class State extends MyEntity
{
...
}
Is there a way to add Field error instead of Form error when validation fails?
In your validator, you have to specifiy the field that was in violation !
with $context->setPropertyPath($propertyPath;
Here is a simple example with field length check