Issue 1:
I have a user entity, which has a password field with several validation constraints attached.

If some of my validation constraint failed, the error message got assigned to the parent form, which should not happen, as the error_bubbling is turned off.

While tracking the problem down, I've came upon this conclusion:

Since it's a registration process, I would like the user to confirm the password he types in order to avoid any mistyping:

$builder->add('password', 'repeated', array(
'type' => 'password',
'invalid_message' => 'The password fields must match.',
'options' => array(
'label' => 'label.password',
'attr' => array(
'class' => 'large_width valid',
)
),
'error_bubbling' => false,
));

I also have some validation constraints about the size of the password and its complexity inside the validation.yml file:

- NotBlank: { groups: [change_password, registration] }
- MinLength: { limit: 6, groups: [change_password, registration] }
- MaxLength: { limit: 200, groups: [change_password, registration ] }

Now, the problem is that the error messages from any validation constraints are not processed as it should - instead of being assigned to the element, they are assigned directly to its form. The reason for this follows:

Symfony\Component\Form\Extension\Validator\Validator\DelegatingValidator:80

foreach ($violations as $violation) {
$propertyPath = $violation->getPropertyPath();
$template = $violation->getMessageTemplate();
$parameters = $violation->getMessageParameters();
$error = new FormError($template, $parameters);

foreach ($mapping as $mappedPath => $child) {
if (preg_match($mappedPath, $propertyPath)) {
$child->addError($error);
continue 2;
}
}

$form->addError($error);
}

In my case, I'm using a main form which has a subform - the one with the user entity attached, thus the $propertyPath value:

$propertyPath = "children[user].data.password"

The important checked paths are:

"/^children\.data\.(?!\w)/"
"/^children\[user\]\.data\.(?!\w)/"
"/^children\[user\]\.data\.username(?!\w)/"
"/^children\[user\]\[password\]\.data\.(?!\w)/"
"/^children\[user\]\[password\]\.data\.first(?!\w)/"
"/^children\[user\]\[password\]\.data\.second(?!\w)/"
"/^children\[user\]\[password\](?!\w)/"
.. some other fields
"/^children\[user\](?!\w)/"

Note that the user.password.first and user.password.second fields are being checked, but not user.password.

Perhaps this case should be added as well:

"/^children\[user\]\.data\.password(?!\w)/"

The last one matched, which obviously is not correct. The reason for the issue seems like that either the repeat form element type was not designed to work with this, either this class was not written with having the repeat field in mind.

Issue 2:
When RepeatedType is nested inside another form, error messages such as "This value should not be blank" bubble up to the root form, instead of appearing above the field in the nested form.

To illustrate this issue, I have put together the following example:

Two types where one is nested in the other (child inside parent).

Both types have the RepeatedType field.

Both RepeatedType fields are NotBlank.

As you can see, the error message for the RepeatedType in the main type, appears right above the fields, but this doesn't happen for the nested type.

Here are the types and models that can be used to demonstrate the issue:

class RegistrationParent
{
public $registrationChild;

/**
* @Assert\NotBlank()
*/
public $plainPassword;
}

class RegistrationChild
{
/**
* @Assert\NotBlank()
*/
public $plainPassword;
}

class RegistrationParentFormType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('registrationChild', new RegistrationChildFormType())
->add('plainPassword', 'repeated', array(
'type' => 'password',
))
;
}

class RegistrationChildFormType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('plainPassword', 'repeated', array(
'type' => 'password',
))
;
}