How to trigger changes on a easyAdmin autocomplete select form after updating option list with an AJAX call?

108 Views Asked by At

I use EasyAdmin 3.5 on a Symfony 5.3.16 project.

I developed a custom easyAdmin page with a symfony form that uses select field.

These fields are emptied and re-filled with some ajax calls from a first select field.

I wanted to add a autocomplete feature on these field. In order to do that, I added this attribute on my formType :

    ->add('customer', EntityType::class, [
                    'class' => Customer::class,
                    'label' => 'OU Client',
                    'required' => false,
                    'placeholder' => 'Sélectionnez un client',
                    'attr' => [
                        'data-ea-widget' => 'ea-autocomplete',
                    ],

The autocomplete attr works very well, but when I made my ajax calls to update options of my select field, My autocomplete does not perform update.

I don't know how to tell my ea-autocomplete attributed field to trigger changes after my ajax call ? What is the javascript command I should use to do so ?

Thanks for your help !

1

There are 1 best solutions below

1
F.Sorgho On

maybe too late but it could help others.

EasyAdmin autocomplete use TomSelect, if you want to edit(add/select/remove) you need to do document.getElementById(your_id).tomselect and use TomSelect apis to do what you want.