Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] Attatching an AbstractComparisonValidator to FormType contains the Form object and throws exception #28987

Closed
@gmponos

Description

@gmponos

Symfony version(s) affected: 4.1.x

Description
When I attach to an object of mine through Yaml or annotation one of the EqualsTo/NotEqualsTo/IdenticalTo/NotIdenticalTo constraints then this line returns the object that the constraint is attached to.

App\Form\Transfer:
    properties:
        from:
            - NotIdenticalTo:
                propertyPath: 'to'

So the line above will return the object App\Form\Transfer

If I add the constraint on a form type like this:

        $builder
            ->add('from', ChoiceType::class, [
                'constraints' => [
                    new NotIdenticalTo(['propertyPath' => 'to']),
                ],
            ])

The line above will bring back a form object.

This causes the constraint to throw an exception because it reaches on this line and in the Form object the path of the property it does not exist.

How to reproduce

Build a form in the way described above and submit it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions