From d6bc96d7dea06a602316673d72b328ddfdcea1b4 Mon Sep 17 00:00:00 2001
From: Kevin Brown
- Yes, Select2 should work with most AMD or CommonJS loaders without any issues.
+ Select2 should work with most AMD- or CommonJS-compliant module loaders, including RequireJS and almond. Select2 ships with a modified version of the UMD jQuery template that supports both CommonJS and AMD environments.
- Due to a bug in older versions of the r.js build tool, Select2 was sometimes placed before jQuery in then compiled build file. Because of this, Select2 will trigger an error because it won't be able to find or load jQuery.
+ Due to a bug in older versions of the r.js build tool, Select2 was sometimes placed before jQuery in then compiled build file. Because of this, Select2 will trigger an error because it won't be able to find or load jQuery.
- You can fix this issue by upgrading to a newer version of the r.js build tool.
+ By upgrading to version 2.1.18 or higher of the r.js build tool, you will be able to fix the issue.
+
+ Select2 internally uses AMD and the r.js build tool to build the files located in the
+ HTML data attributes are case-insensitive, so any options which contain capital letters will be parsed as if they were all lowercase. Because Select2 has many options which are camelCase, where words are separated by uppercase letters, you must write these options out with dashes instead. So an option that would normally be called
This means that if you declare your
+ Select2 will register itself as a jQuery function if you use any of the distribution builds, so you can call
+ You can optionally pass an object containing all of the options that you would like to initialize Select2 with.
+
@@ -29,10 +29,18 @@ $.fn.select2.defaults.set('amdLanguageBase', 'select2/i18n/');
+ Should I point to the files in
+
+ dist
or src
?
+ dist
folder. These are built using the files in the src
folder, so you can just point your modules to the Select2 source and load in jquery.select2
or select2/core
when you want to use Select2. The files located in the dist
folder are also AMD-compatible, so you can point to that file if you want to load in all of the default Select2 modules.
camelCase
options be written?
+ allowClear
should instead be defined as allow-clear
.
+ <select>
tag as...
.select2()
on any jQuery element where you would like to initialize Select2.
+
+$('select').select2();
+
+
+
+$('select').select2({
+ placeholder: 'Select an option'
+});
+
+
Can default options be set for all dropdowns?
@@ -44,12 +62,16 @@ $.fn.select2.defaults.set("theme", "classic");
string.
+$.fn.select2.defaults.set("ajax--cache", false); ++
- You can reset the default options by calling + You can reset the default options to their initial values by calling