Closed
Description
Every time when i need to return form errors to json I need to transform manually errors in my controller like:
/** @var array $errors */
$errors = array();
/** @var FormError $error */
foreach($form->getErrors(true) as $error)
{
$errors[] = array('message'=>$error->getMessage());
}
$response = new JsonResponse();
$response->setData(array(
'errors' => $errors
));
but with this simple implementation we can do:
/** @var JsonResponse $response */
$response = new JsonResponse();
$response->setData(array(
'form'=>array(
'errors' => $form->getErrors(true)
)
));
I do not see if this implementation can have any adverse side effect.