How to integrate jQuery select2 library into a Symfony3 form?
<p>I am trying to manually integrate the jQuery <a href="https://select2.github.io/" rel="nofollow"><code>select2</code></a> library into my Symfony form as a replacement for my select boxes.</p>

<p>Following the manual I have added to the page header:</p>

<pre><code>&lt;link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2-rc.1/css/select2.min.css" rel="stylesheet" /&gt;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2-rc.1/js/select2.min.js"&gt;&lt;/script&gt;
</code></pre>

<p>In addition I have modified my form class, adding <code>attr</code> to each select:</p>

<pre><code>-&gt;add('kontoWinien', EntityType::class, array(
    'class' =&gt; 'AppBundle\Entity\konto',
    'attr' =&gt; array('class'=&gt;'select2')
))
</code></pre>

<p>My modified Twig template:</p>

<pre><code>{{ form_start(form) }}
&lt;SCRIPT type="text/javascript"&gt;
     $(document).ready(function() {
        $(".select2").select2();
    });
&lt;/SCRIPT&gt;
{{ form_widget(form) }}
{{ form_end(form) }}
</code></pre>

<p>However <strong>the select2 is still not loaded</strong>. </p>

<p>HTML code generated by symfony3 looks like this:</p>

<pre><code> &lt;head&gt;
    &lt;link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2-rc.1/css/select2.min.css" rel="stylesheet" /&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2-rc.1/js/select2.min.js"&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;form name="dziennik" method="post"&gt;
&lt;script type="text/javascript"&gt;
    $(document).ready(function() {
        $(".select2").select2();
    });
&lt;/script&gt;

&lt;select id="dziennik_kontoWinien" name="dziennik[kontoWinien]" class="select2 form-control"&gt;
</code></pre>

<p>Could you please advise what am i doing wrong?</p>