tetranz / select2entity-bundle

A Symfony2 bundle that integrates Select2 as a drop-in replacement for a standard entity field on a Symfony form.
MIT License
218 stars 111 forks source link

Initialize error javascript #188

Open Saikurin opened 2 years ago

Saikurin commented 2 years ago

When I initialize my select2 field, i have a JS error : $s2.select2 is not a function I'm using "tetranz/select2entity-bundle": "^3.1" and I have executed bin/console assets:install

I add this line in my javascript block :

<script src="{{ asset('bundles/tetranzselect2entity/js/select2entity.js') }}"></script>

And this is my form class :

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('zone', Select2EntityType::class, [
                'class' => Zone::class,
                'primary_key' => 'id',
                'text_property' => 'name',
                'multiple' => true,
                'allow_clear' => true,
                'language' => 'fr',
                'remote_route' => 'folder_select2_zone',
            ]);
    }

I don't think it's related but this is my route 'folder_select2_zone' :

     /**
     * @Route("/folder/select2_zone", name="folder_select2_zone")
     */
    public function select2Zone()
    {
        return new JsonResponse([
            [
                'id' => 1,
                'name' => 'toto'
            ]
        ]);
    }