Skip to content

Initialize error javascript #188

Description

@Saikurin

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'
            ]
        ]);
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions