I have a Silex project where i use the FormServiceProvider and ValidatorServiceProvider. I have made a form with the form.factory builder, added fields, and use an object as dataset:
$form = $app['form.factory']->createBuilder('form', $object)
I then try to validate the form on submition the "normal way":
if ($app['request']->getMethod() == 'POST') {
$form->bind($app['request']);
if ($form->isValid()) {
(...)
}
}
In the object, i have added a loadValidatorMetadata static method:
static public function loadValidatorMetadata(ClassMetadata $metadata) {
$metadata->addPropertyConstraint('name', new Assert\MinLength(5, array('message' => 'Name too short')));
}
When I submit the form with a shorter name field, isValid still return true. If I run a validate method on the object like this:
$errors = $app['validator']->validate($object)
it returns an error based on the constraint, but the form isValid does not find this error. When i looked into the symfony Form class, i found that isValid skips checking child fields when the disable config is true. This is the case for my form, but I have no idea why. I have just registered the Silex service providers the normal way without any special config. Any idea how to make the form fail validation based on the object constraints?