Cephalopodius
Cephalopodius

Reputation: 125

Autocomplete option on filter with EasyAdmin 3.3

I would like to know if in easyadmin 3.3 there is an quick solution to use an autocomplete option on filter. It work fine on form but not with the filter, it return an undefined error.

  public function configureFields(string $pageName): iterable
    {
        return [
            AssociationField::new('entity1')->autocomplete(true),
            AssociationField::new('entity2'),
}

     public function configureFilters(Filters $filters): Filters
        {
          return $filters
    
            ->add(EntityFilter::new('entity1')->setFormTypeOption('value_type_options', 
             ['multiple'=> true]))
    
            ->add(EntityFilter::new('entity2'))
    
            ;
        }

I dont find a lot of code about this (with this version). I know easyadmin 3.4 can solve this , but upgrading need to adapt a lot of code with bootstrap 5 and the end of jquery using.

Upvotes: 0

Views: 1204

Answers (1)

Flash
Flash

Reputation: 1204

Not really an autocomplete for filters but you can add js code like this to make them select2 for easy search of an option you need

$('#modal-filters').on('shown.bs.modal', e => {
   console.log(e);
   setTimeout(makeSelect2, 100);
});

function makeSelect2 () {
   if (document.getElementById('filters')) {
      $('.filter-field [data-widget=select2]').select2({
         theme: 'bootstrap',
         placeholder: 'Select',
         allowClear: true
      });
   } else {
      setTimeout(makeSelect2, 100);
   }
}

Upvotes: 1

Related Questions