Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

DateRangeFilterType Constraint validation violation bubbles to form #287

Open
antoniocambados opened this issue Mar 22, 2018 · 0 comments
Open

Comments

@antoniocambados
Copy link

I'm experiencing an issue with the DateRangeFilterType. I'm assigning some validation constraints to such a field and whenever a violation is raised, errors won't be assigned to the field and rendered accordingly. Instead, the errors will bubble to the parent form and be rendered at that level.

I'll leave here an example. Given a simple form like the one below:

class FooFilterType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('foo', EntityFilterType::class, [
                'class'          => Foo::class,
                'constraints' => [
                    new Expression("this === null"),
                ],
            ])
            ->add('dateRange', DateRangeFilterType::class, [
                'left_date_options' => [
                    'data'   => new \DateTime('1 month ago midnight'),
                    'widget' => 'single_text',
                ],
                'right_date_options' => [
                    'data'   => new \DateTime('today midnight'),
                    'widget' => 'single_text',
                ],
                'constraints' => [
                    new Expression("value['left_date'] <= value['right_date']"),
                ],
            ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'method'            => Request::METHOD_GET,
            'csrf_protection'   => false,
            // 'validation_groups' => ['filtering'],
        ]);
    }
}

If sent a request that would trigger violations for both constraints, you would get some output like the following:

seleccion_659

I've included in the output the vars.errors for the form and both fields, as well as the cause.propertyPath for every error.

Here you can see that the dateRange field has no mapped errors and those were bubbled to the parent form, even though the property path is virtually identical to the error for the field foo which is correctly assigned.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant