EasyAdminBundle
EasyAdminBundle copied to clipboard
Validation errors on filters
Describe the bug I want to filter Offer entity by their Product entity without validation errors
To Reproduce I'm using EasyAdmin 3. I have Product, VatRate and Offer entities. Product entity has ManyToOne VatRate with NotBlank constraint and OneToMany Offer entity. When I want to display list of Offers with specific Product then in filters at Product field I see "This value should not be blank" (because VatRate is required on Product entity, but it should not be required on filters)
(OPTIONAL) Additional context I'm trying to decorate EasyCorp\Bundle\EasyAdminBundle\Factory\FormFactory to add 'validation_grops' => ['Admin'] at createFiltersForm but this not work, because FormFactory type hint does not have an interface and fails in EasyCorp\Bundle\EasyAdminBundle\Orm\EntityRepository
I'm pretty sure that if you want to modify validation groups you'll use the getCrud -> newForm/editForm options instead.
Thanks @pkly, but the problem is in filters form, which is in list view.
oh, my bad why would that be even displayed if all it's supposed to be is just applying filters to the index query? this is kinda weird, can you share your configureFilters method and possibly other code you changed?
I've checked that if I remove @Assert\NotBlank from my vatRate (ManyToOne VatRate) in Product then it works. I think this is because FormFactory has $form->isValid()
doesn't that just mean that your entity is invalid in the first place?
I'll prepare fork from admin demo for that
Ok, I have that, please clone this https://github.com/cve/easyadmin-demo/tree/filter_not_valid, run and try to use author filter on blog posts and you should see that:

@pkly Did You see that?
No, sorry, I'm currently busy with work and cannot check this. But like I said before, my guess is that the entities you're using are just invaliid, that is their validation rules are not matching up with the expected state that was persisted, and this you're getting this error since it's dubbling up from the entity.
Btw you shouldn't put things like @Assert\NotBlank() on ManyToOne afaik.
https://github.com/cve/easyadmin-demo/blob/9bbeb25539d3606150776c76e27ba15d88d14eb0/src/Entity/User.php#L86
I'm guessing this error occurs since you have nothing there, or in some other field that has the @Assert\NotBlank annotation.
Today encountered same issue. I think the biggest problem here is that "Filter Form" does not define it's own Validation Group and it's caused that "Default" group is validated.
As an example we have EntityFilter (which is used to filter "parent" in category tree), which is checking entire entity including Callback constraints.
I think solution for this is to allow to configure "validation_groups" in \EasyCorp\Bundle\EasyAdminBundle\Dto\FilterConfigDto and later re-use it when building \EasyCorp\Bundle\EasyAdminBundle\Form\Type\FiltersFormType
Fast solution could be the following: https://github.com/EasyCorp/EasyAdminBundle/issues/4842#issuecomment-1377644859