Skip to content

Commit

Permalink
bug #3778 [FIX] autocomplete url can have a wrong 'sort' query parame…
Browse files Browse the repository at this point in the history
…ter (Yondz)

This PR was merged into the 3.0.x-dev branch.

Discussion
----------

[FIX] autocomplete url can have a wrong 'sort' query parameter

Hi,

I've encountered a bug while using [easy-admin-demo](https://github.com/javiereguiluz/easy-admin-demo), the autocomplete field of an entity non sortable (`Category` for instance) on a create/edit form for another entity wich has a custom sort (`Product` in that case) was broken.

It appears that the URL generated for that AJAX call contains a `sort` query parameter taken from the current view (`Product` then), which will somehow be injected in the `SearchDto`, leading to a Doctrine-related error if this field does not exist on the autocompleted entity (`Category`).

To reproduce, you can use easy-admin-demo with an updated database schema, you should get an error while trying to autocomplete a `Category` when editing a `Product`.

I'm not sure it's the way to go to fix this, but I tried to keep things as simple as possible to avoid regressions elsewhere, feedbacks welcomed !

This could be related to #3695 as well.

See ya ;)

Commits
-------

9747b49 [FIX] autocomplete url can have a wrong 'sort' query parameter
  • Loading branch information
javiereguiluz committed Sep 26, 2020
2 parents cb62416 + 9747b49 commit b6ec7c3
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/Field/Configurator/AssociationConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
->setController($field->getCustomOption(AssociationField::OPTION_CRUD_CONTROLLER))
->setAction('autocomplete')
->setEntityId(null)
->unset('sort') // Avoid passing the 'sort' param from the current entity to the autocompleted one
->generateUrl();

$field->setFormTypeOption('attr.data-ea-autocomplete-endpoint-url', $autocompleteEndpointUrl);
Expand Down

0 comments on commit b6ec7c3

Please sign in to comment.