How to get this full propertyPath? Need this to add validation cases in jQuery, because I've rewrite legacy application into new SF4 application. Odx2ParameterCollectionType is a collection with dynamic fields.
Is there any way to get this validation errors? Maybe You've other solutions how to work with it?
protected function renderFormErrors(FormInterface $form): JsonResponse
{
$errors = [];
foreach ($form->getErrors(true) as $error) {
$errors[$error->getOrigin()->getName()] = $error->getMessage();
}
return $this->json([
self::RETURN_PARAMETER_STATUS => Response::HTTP_INTERNAL_SERVER_ERROR,
self::RETURN_PARAMETER_ERRORS => $errors
]);
}
Actual:
{
"status": 500,
"errors": {
"udsId": "This value should not be blank."
}
}
Expected:
{
"status": 500,
"errors": {
"Odx2ParameterCollectionType[parameters][5][udsId]": "This value should not be blank."
}
}
EDIT:
Ok, I've figure it out, but for now I've one missing thing - index of collection, it's my code:
foreach ($form->all() as $name => $child) {
if (!$child->isValid()) {
foreach ($child->getErrors(true) as $error) {
$errors[(string) $form->getPropertyPath()][$name][$error->getOrigin()->getName()] = $error->getMessage();
}
}
}