I have controller action like this:
public function createAction()
{
$entity = new Client();
$request = $this->getRequest();
$form = $this->createForm(new ClientType(), $entity);
$form->bindRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('client_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView()
);
}
The underlying Client Entity has a field type witch can take values [0, 1] now, I have defined the 2 validation groups for Client entity: person and company.
How can I change/choose validation group based on user entered value into type field?
You can add a callback validation constraint for your class (Client entity), from the docs: