Using autocompletes

The SyliusBootstrapAdminUi package uses Symfony UX arrow-up-rightunder the hood. Thus, UX autocompletearrow-up-right is already setup and configured in your admin panel. This means that any simple ChoiceType filter form can be turned into an autocomplete simply by setting autocomplete to true in form options.

public function configureOptions(OptionsResolver $resolver): void
{
        $resolver->setDefaults([
            'choices' => $this->getChoices(),
            'placeholder' => 'sylius.ui.all',
            'autocomplete' => true,
        ]);
}

public function getParent(): string
{
    return ChoiceType::class;
}

However, if your autocomplete filter requires fetching data from another entity, you will need to use a BaseEntityAutocompleteType in order to fetch your options via AJAX.

All you need to start leveraging this functionality is a bit of routing config.

Configure the entity autocomplete route

config/routes/ux_autocomplete.php
<?php

declare(strict_types=1);

use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return static function (RoutingConfigurator $routingConfigurator): void {
    // ...
    $routingConfigurator
        ->add('ux_entity_autocomplete_admin', '/admin/autocomplete/{alias}')
        ->controller('ux.autocomplete.entity_autocomplete_controller')
    ;
};

This adds a new ux_entity_autocomplete_admin AJAX route dedicated to your autocompletes.

Add a grid filter with entity autocomplete

First, you need to create an entity autocomplete field arrow-up-right.

Then, you need to create your grid filter.

Now that the filter is configured, you can use it inside any grid.

Last updated

Was this helpful?