You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have entity Client witch have field type, that field can hold 2 values (const TYPE_PERSON or TYPE_COMPANY), also I have 2 validation groups person and company, because ie. different fields are required based on client type.
Now standard way of creating new client looks like this:
public action clientCreateAction()
{
$client = new Entity\Client();
$form = $this->createForm(new ClientType(), $client);
$form->bindRequest($this->getRequest());
if($form->isValid())
// persis object
}
In this scenario, because validation is called by the $form->bindRequest() I'm not able to set correct validation groups without using $data = $this->getRequest()->request->get($form->getName()); $type = $data['type']; and injecting this value into ClientType
That process of determining validation groups based on any value should natural and easy with form/validation framework.
My suggest solution is to enable developer to use closure as value of $options['validation_groups'] eg:
class ClientType extends AbstarctType
{
// ...
public function getDefaultOptions(array $options)
{
return array(
'validation_groups' => function($dataFromRequest, $objectTainedToType){
// return array of validation groups that should be used to validate given data / object pair
},
);
}
// ...
}
The text was updated successfully, but these errors were encountered:
Consider following example:
I have entity
Client
witch have fieldtype
, that field can hold 2 values (const TYPE_PERSON or TYPE_COMPANY), also I have 2 validation groupsperson
andcompany
, because ie. different fields are required based on client type.Now standard way of creating new client looks like this:
In this scenario, because validation is called by the
$form->bindRequest()
I'm not able to set correct validation groups without using$data = $this->getRequest()->request->get($form->getName()); $type = $data['type'];
and injecting this value intoClientType
That process of determining validation groups based on any value should natural and easy with form/validation framework.
My suggest solution is to enable developer to use closure as value of
$options['validation_groups']
eg:The text was updated successfully, but these errors were encountered: