EDITED
1º You need to create a custom TWIG template for it (where you could place your javascript code just before the widget code).
2º Then you write inside ap/config/config.yml
where your custom template is to allow Symfony and SonataAdmin to recognize it.
1º You have some info here Sonata Admin - Custom template
2º More info here customize field types
An example could be something like this:
Admin class
protected function configureFormFields(FormMapper $formMapper) {
$formMapper
->add('name', 'ajax_autocomplete')
->add('description', 'text')
;
}
And, in the TWIG template you need to extend from the Sonata Admin field template that better fits your necessities. In this case maybe base_edit.html.twig
or edit_text.html.twig
You have a list of templates to extend from, inside this Sonata Admin dir: vendor\sonata-project\admin-bundle\Sonata\AdminBundle\Resources\views\CRUD
Customization
Imagine you have placed your custom template inside XXXBundle:YYY:ajax_autocomplete.html.twig
I think it should work if you write a line here:
sonata_doctrine_orm_admin:
templates:
types:
list:
ajax_autocomplete: XXXBundle:YYY:ajax_autocomplete.html.twig
name
field in this case)? Can you tell me more about what do you want to do? – Amide