symfony/symfony — Issue #2801: Collection Callback validation error bubbling to the root form, should stay with field
Author: PorridgeBear
Created: 2011-12-08 01:26:01+00:00
State: open

I have seen similar bug reports, apologies if this is a duplicate. In my case, when I am using a collection field as follows:

```php
$builder->add('goods', 'collection', array(
'type' => new GoodType(),
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'by_reference' => false
));
```

And a callback validator

```yml
constraints:
- Callback:
methods: [checkGoods]
```

```php
/**
* Callback validator for Goods
* @param ExecutionContext $context
*/
public function checkGoods(\Symfony\Component\Validator\ExecutionContext $context) {
if (! is_null($this->goods) && $this->goods->count() == 0) {
$propertyPath = $context->getPropertyPath() . '.goods';
$context->setPropertyPath($propertyPath);
$context->addViolation('Please provide at least one good', array(), null);
}
}
```

I see the "Please provide at least one good" at the root of the form, where

```text
{{ form_errors(form) }}
```

is called, but I expect it to be output with the field itself, presumably in the div that contains the data-prototype definition.