Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing Select2 throws define is not defined error

When I download the 4.0.1 Release Candidate (https://github.com/select2/select2/releases/tag/4.0.1-rc.1) of Select2 and use it, I get a JavaScript error: Uncaught ReferenceError: define is not defined.

Here I read that it has to do with the AMD loader (which I don't use): https://groups.google.com/forum/#!topic/select2/PCQpiJxIIXQ

When I don't use the jquery.select2.js from the RC, but the select2.min.js from the current master: https://raw.githubusercontent.com/select2/select2/master/dist/js/select2.min.js

it works!

But I'm curious what I overlook here. Most likely I'm doing something wrong myself.

Edit - code example:

in the head:

<script language='Javascript' src='scripts/jquery-1.9.1.min.js'></script>
<script language='Javascript' src='scripts/jquery.select2.js'></script>

in the body:

<script type="text/javascript"> 

    $(document).ready(function(){       

    $('#id_of_select').select2({
      tags: "true",
      placeholder: "",
      allowClear: true,
      tokenSeparators: [',', ' ']
    });
});
</script>

<select multiple id="id_of_select" name="name[]">
    <option value="1" selected="">Option 1</option>
    <option value="2" selected="">Option 2</option>
    <option value="5">Option 3</option>
</select>
like image 550
11mb Avatar asked Nov 10 '15 09:11

11mb


1 Answers

Ok, my bad it is.. in the folder structure of the select2 package there are several folders including:

  • dist
  • src

I used the javascript from the src folder.. But it seems the right files are in the dist folder.

like image 108
11mb Avatar answered Oct 05 '22 23:10

11mb