-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter autocomplete results #1629
Comments
Not yet, but likely it would be a nice feature to implement :) |
However, you can always override the protected function autocompleteAction()
{
if ('Lugar' === $this->request->query->get('entity')) {
$results = // make custom query and see Autocomplete class to know how to parse the results.
return new JsonResponse($results);
}
return parent::autocompleteAction();
} |
@javiereguiluz could be nice make public the |
More and more people are asking this ... so I guess it makes sense. I'm still thinking about it. Thanks! |
Yeah I've done this by passing an additional argument to autocompleteAction, so my controller:
And overriding the default search action:
Is a little long, but it works |
@blackatze93 great! This would make this configuration happy, something like this: easy_admin:
entities:
Product:
class: AppBundle\Entity\Product
form:
fields:
- { property: 'category', type: 'easyadmin_autocomplete', type_options: { dql_filter: 'entity.enabled = true' } }
# ...
# ... |
@yceruto This would be awesome! |
Would it be possible to filter the autocomplete depending on the entity you are editing ? |
@erichard No that isn't possible directly. Since you only get the following details from the request object:
Additionally it's not possible to join before filtering. You can only filter on already joined associations with |
I'm closing this issue because we're starting a new phase in the history of this bundle (see #2059). We've moved it into a new GitHub organization and we need to start from scratch: no past issues, no pending pull requests, etc. I understand if you are angry or disappointed by this, but we really need to "reset" everything in order to reignite the development of this bundle. |
I know this thread is closed but never found a good solution, mine doesn't use autocomplete, but you can filter the multi-select associated entities. I am still looking for a non-intrusive way to do it for autocomplete. protected function createEntityFormBuilder($entity, $view)
{
$formBuilder = parent::createEntityFormBuilder($entity, $view);
if (!$this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) {
$user = $this->get('security.token_storage')->getToken()->getUser();
$promoter = $this->getDoctrine()
->getRepository(Promoter::class)
->findByUser($user);
$queryBuilder = $this->getDoctrine()
->getRepository(Customer::class)
->getActiveByPromoterQueryBuilder($promoter);
$formBuilder->add(
'customers', EntityType::class, [
'class' => Customer::class,
'query_builder' => $queryBuilder,
"attr" => ["class" => "form-control select2", "data-widget" => "select2"],
'by_reference' => false,
'multiple' => true,
'required' => false
]
);
}
return $formBuilder;
} The key is in vendor/easycorp/easyadmin-bundle/src/Resources/views/default/includes/_select2_widget.html.twig. Just add the data-widget attribute to form field. |
Take a look at this proposal #2598 adding the sort and dql_filter options for autocomplete results, any feedback is welcomed :) |
If there any way to filter the results of the autocomplete action?
For example I have
and I need in that in the autocomplete field only shows the Lugar results that have a boolean property to true:
Any idea? (Sorry for my bad english)
The text was updated successfully, but these errors were encountered: