From d6bc96d7dea06a602316673d72b328ddfdcea1b4 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Thu, 14 Jan 2016 18:40:37 -0500 Subject: [PATCH] Expand upon the core section of the docs This adds more code examples where they might be useful, and adds some more description where it was needed. This clarifies a couple of the questions that have come up about the AMD support and links to the bug that Select2 was involved with that some people reported when 4.0.0 was released. --- docs/_includes/options/core/amd-support.html | 14 ++++++++--- .../options/core/data-attributes.html | 6 ++++- docs/_includes/options/core/options.html | 24 ++++++++++++++++++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/docs/_includes/options/core/amd-support.html b/docs/_includes/options/core/amd-support.html index 9dfd2759..faa23246 100644 --- a/docs/_includes/options/core/amd-support.html +++ b/docs/_includes/options/core/amd-support.html @@ -4,7 +4,7 @@

- 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.

@@ -29,10 +29,18 @@ $.fn.select2.defaults.set('amdLanguageBase', 'select2/i18n/');

- 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. +

+ +

+ Should I point to the files in dist or src? +

+ +

+ Select2 internally uses AMD and the r.js build tool to build the files located in the 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.

\ No newline at end of file diff --git a/docs/_includes/options/core/data-attributes.html b/docs/_includes/options/core/data-attributes.html index 9a95e105..357bfaa9 100644 --- a/docs/_includes/options/core/data-attributes.html +++ b/docs/_includes/options/core/data-attributes.html @@ -14,6 +14,10 @@ How should camelCase options be written? +

+ 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 allowClear should instead be defined as allow-clear. +

+

This means that if you declare your <select> tag as...

@@ -59,7 +63,7 @@ $("select").select2({ $("select").select2({ ajax: { url: "http://example.org/api/test", - cache: "true" + cache: true } }); diff --git a/docs/_includes/options/core/options.html b/docs/_includes/options/core/options.html index 2b7cb1f4..8f712626 100644 --- a/docs/_includes/options/core/options.html +++ b/docs/_includes/options/core/options.html @@ -3,6 +3,24 @@ How should Select2 be initialized? +

+ Select2 will register itself as a jQuery function if you use any of the distribution builds, so you can call .select2() on any jQuery element where you would like to initialize Select2. +

+ +
+$('select').select2();
+
+ +

+ You can optionally pass an object containing all of the options that you would like to initialize Select2 with. +

+ +
+$('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);
+
+

How can I reset all of the global default options?

- You can reset the default options by calling + You can reset the default options to their initial values by calling