` if you are using a single select.
diff --git a/pages/10.searching/docs.md b/pages/10.searching/docs.md
new file mode 100644
index 00000000..04b48227
--- /dev/null
+++ b/pages/10.searching/docs.md
@@ -0,0 +1,150 @@
+---
+title: Search
+taxonomy:
+ category: docs
+process:
+ twig: true
+never_cache_twig: true
+---
+
+The appearance and behavior of the search control can be easily customized with Select2.
+
+## Customizing how results are matched
+
+When users filter down the results by entering search terms into the search box, Select2 uses an internal "matcher" to match search terms to results. You may customize the way that Select2 matches search terms by specifying a callback for the `matcher` configuration option.
+
+Select2 will pass each option as represented by its [internal representation](/options) into this callback to determine if it should be displayed:
+
+```
+function matchCustom(params, data) {
+ // If there are no search terms, return all of the data
+ if ($.trim(params.term) === '') {
+ return data;
+ }
+
+ // `params.term` should be the term that is used for searching
+ // `data.text` is the text that is displayed for the data object
+ if (data.text.indexOf(params.term) > -1) {
+ var modifiedData = $.extend({}, data, true);
+ modifiedData.text += ' (matched)';
+
+ // You can return modified objects from here
+ // This includes matching the `children` how you want in nested data sets
+ return modifiedData;
+ }
+
+ // Return `null` if the term should not be displayed
+ return null;
+}
+
+$(".js-example-matcher").select2({
+ matcher: matchCustom
+});
+```
+
+>>>> When a remote data set is used, Select2 expects that the returned results have already been filtered.
+
+### Matching grouped options
+
+Only first-level objects will be passed in to the `matcher` callback. If you are working with nested data, you must iterate through the `children` array and match them individually. This allows for more advanced matching when working with nested objects, allowing you to handle them however you want.
+
+This example matches results only if the term appears in the beginning of the string:
+
+
+
+
+
+
+
+
+
+>>> A [compatibility module]() exists for using v3-style matcher callbacks.
+
+## Minimum search term length
+
+Sometimes when working with large data sets, it is more efficient to start filtering the results only when the search term is a certain length. This is very common when working with remote data sets, as it allows for only significant search terms to be used.
+
+You may set a minimum search term length by using the `minimumInputLength` option:
+
+```
+$('select').select2({
+ minimumInputLength: 3 // only start searching when the user has input 3 or more characters
+});
+```
+
+## Maximum search term length
+
+In some cases, search terms need to be limited to a certain range. Select2 allows you to limit the length of the search term such that it does not exceed a certain length.
+
+You may limit the maximum length of search terms by using the `maximumInputLength` option:
+
+```
+$('select').select2({
+ maximumInputLength: 20 // only allow terms up to 20 characters long
+});
+```
+
+## Limiting display of the search box to large result sets
+
+The `minimumResultsForSearch` option determines the minimum number of results required in the initial population of the dropdown to display the search box.
+
+This option is useful for cases where local data is used with a small result set, and the search box would simply be a waste of screen real estate. Set this value to -1 to permanently hide the search box.
+
+```
+$('select').select2({
+ minimumResultsForSearch: 20 // at least 20 results must be displayed
+});
+```
+
+## Hiding the search box
+
+Select2 allows you to hide the search box depending on the number of options which are displayed. In this example, we use the value `Infinity` to tell Select2 to never display the search box.
+
+
+
+
+
+
+
+
diff --git a/pages/10.programmatic-control/01.methods/docs.md b/pages/11.programmatic-control/01.methods/docs.md
similarity index 100%
rename from pages/10.programmatic-control/01.methods/docs.md
rename to pages/11.programmatic-control/01.methods/docs.md
diff --git a/pages/10.programmatic-control/02.events/docs.md b/pages/11.programmatic-control/02.events/docs.md
similarity index 100%
rename from pages/10.programmatic-control/02.events/docs.md
rename to pages/11.programmatic-control/02.events/docs.md
diff --git a/pages/10.programmatic-control/chapter.md b/pages/11.programmatic-control/chapter.md
similarity index 85%
rename from pages/10.programmatic-control/chapter.md
rename to pages/11.programmatic-control/chapter.md
index 397aec54..78e1da06 100644
--- a/pages/10.programmatic-control/chapter.md
+++ b/pages/11.programmatic-control/chapter.md
@@ -4,6 +4,4 @@ taxonomy:
category: docs
---
-### Chapter 3
-
# Programmatic Control
diff --git a/pages/12.advanced/adapters.html b/pages/12.advanced/adapters.html
deleted file mode 100644
index c0807ede..00000000
--- a/pages/12.advanced/adapters.html
+++ /dev/null
@@ -1,209 +0,0 @@
-
-
-
-
- Select2 allows plugins to add additional functionality through the core
- adapters. You can change almost anything involving the way Select2 works
- to the way Select2 interacts with the page by modifying the core adapters.
- Most third-party plugins should provide decorators (used to wrap adapters)
- and custom adapters that you can use.
-
-
-
- Each adapter contains a set of methods which will must always be defined.
- Along with the global methods that all adapters must implement, these
- methods must be implemented.
-
-
-
- All adapters
-
-
-
- All adapters must implement a set of methods that Select2 will use to
- display them and bind any internal events.
-
-
-
-// The basic HTML that should be rendered by Select2. A jQuery or DOM element
-// should be returned, which will automatically be placed by Select2 within the
-// DOM.
-//
-// @returns A jQuery or DOM element that contains any elements that must be
-// rendered by Select2.
-Adapter.render = function () {
- return $jq;
-};
-
-// Bind to any Select2 or DOM events.
-//
-// @param container The Select2 object that is bound to the jQuery element. You
-// can listen to Select2 events with `on` and trigger Select2 events using the
-// `trigger` method.
-// @param $container The jQuery DOM node that all default adapters will be
-// rendered within.
-Adapter.bind = function (container, $container) { };
-
-// Position the DOM element within the Select2 DOM container, or in another
-// place. This allows adapters to be located outside of the Select2 DOM,
-// such as at the end of the document or in a specific place within the Select2
-// DOM node.
-//
-// Note: This method is not called on data adapters.
-//
-// @param $rendered The rendered DOM element that was returned from the call to
-// `render`. This may have been modified by Select2, but the root element
-// will always be the same.
-// @param $defaultContainer The default container that Select2 will typically
-// place the rendered DOM element within. For most adapters, this is the
-// Select2 DOM element.
-Adapter.position = function ($rendered, $defaultContainer) { };
-
-// Destroy any events or DOM elements that have been created.
-// This is called when `select2("destroy")` is called on an element.
-Adapter.destroy = function () { };
-
-
-
- Container (selection)
-
-
-
- The selection is what is shown to the user as a replacement of the
- standard <select>
box. It controls the display of the
- selection option(s), as well anything else that needs to be embedded
- within the container, such as a search box.
-
-
-
- Key
-
- selectionAdapter
-
-
- Default
-
- SingleSelection
or
- MultipleSelection
-
-
- Base
-
- BaseSelection
-
-
-
-
-// Update the selected data.
-//
-// @param data An array of data objects that have been generated by the data
-// adapter. If no objects should be selected, an empty array will be passed.
-//
-// Note: An array will always be passed into this method, even if Select2 is
-// attached to a source which only accepts a single selection.
-SelectionAdapter.update = function (data) { };
-
-
-
- Data set
-
-
-
- The data set is what Select2 uses to generate the possible results that
- can be selected, as well as the currently selected results.
-
-
-
- Key
-
- dataAdapter
-
-
- Default
-
- SelectAdapter
-
-
- Base
-
- BaseAdapter
-
-
-
-
-// Get the currently selected options. This is called when trying to get the
-// initial selection for Select2, as well as when Select2 needs to determine
-// what options within the results are selected.
-//
-// @param callback A function that should be called when the current selection
-// has been retrieved. The first parameter to the function should be an array
-// of data objects.
-DataAdapter.current = function (callback) {
- callback(currentData);
-}
-
-// Get a set of options that are filtered based on the parameters that have
-// been passed on in.
-//
-// @param params An object containing any number of parameters that the query
-// could be affected by. Only the core parameters will be documented.
-// @param params.term A user-supplied term. This is typically the value of the
-// search box, if one exists, but can also be an empty string or null value.
-// @param params.page The specific page that should be loaded. This is typically
-// provided when working with remote data sets, which rely on pagination to
-// determine what objects should be displayed.
-// @param callback The function that should be called with the queried results.
-DataAdapter.query = function (params, callback) {
- callback(queryiedData);
-}
-
-
-
- Dropdown
-
-
-
- The dropdown adapter defines the main container that the dropdown should
- be held in. It does not define any extra methods that can be used
- for decorators , but it is common for decorators to attach to the
- render
and position
methods to alter how the
- dropdown is altered and positioned.
-
-
-
- Key
-
- dropdownAdapter
-
-
- Default
-
- DropdownAdapter
-
-
-
-
- Results
-
-
-
- The results adapter controls the list of results that the user can select
- from. While the results adapter does not define any additional methods
- that must be implemented, it makes extensive use of the Select2 event
- system for controlling the display of results and messages.
-
-
-
- Key
-
- resultsAdapter
-
-
- Default
-
- ResultsAdapter
-
-
-
diff --git a/pages/12.advanced/core-options.html b/pages/12.advanced/core-options.html
deleted file mode 100644
index c32ca56f..00000000
--- a/pages/12.advanced/core-options.html
+++ /dev/null
@@ -1,790 +0,0 @@
-
-
-
-
- Select2 supports a small subset of options in every build that is
- generated. Each option typically has a decorator that is required that
- wraps an adapter, adding support for the option. This is only required
- when a custom adapter is being used, as Select2 will build the required
- adapters by default.
-
-
-
- Select2 will automatically apply decorators to any adapters which have not
- been manually overridden. The only time you need to decorate adapters is
- when you are using third-party adapters not provided by Select2, or you
- are using features not provided in the Select2 core. You can apply a
- decorator to an adapter using the
- Utils.Decorate
method provided with
- Select2.
-
-
-
-$.fn.select2.amd.require(
- ["select2/utils", "select2/selection/single", "select2/selection/placeholder"],
- function (Utils, SingleSelection, Placeholder) {
- var CustomSelectionAdapter = Utils.Decorate(SingleSelection, Placeholder);
-});
-
-
-
- All core options that use decorators or adapters will clearly state it
- in the "Decorator" or "Adapter" part of the documentation. Decorators are
- typically only compatible with a specific type of adapter, so make sure to
- note what adapter is given.
-
-
-
- Declaring configuration in the data-*
attributes
-
-
-
- It is recommended that you declare your configuration options for Select2
- when initializing Select2. You can also define your configuration options
- by using the HTML5 data-*
attributes, which will override
- any options set when initializing Select2 and any defaults.
-
-
-
- This means that if you declare your <select>
tag as...
-
-
-
-<select data-tags="true" data-placeholder="Select an option"></select>
-
-
-
- Will be interpreted the same as initializing Select2 as...
-
-
-
-$("select").select2({
- tags: "true",
- placeholder: "Select an option"
-});
-
-
-
- You can also define nested configurations, which are typically needed for
- options such as AJAX. Each level of nesting should be separated by two
- dashes (--
) instead of one. Due to
- a jQuery bug ,
- nested options using data-*
attributes
- do not work in jQuery 1.x .
-
-
-
-<select data-ajax--url="http://example.org/api/test" data-ajax--cache="true"></select>
-
-
-
- Which will be interpreted the same as initializing Select2 with...
-
-
-
-$("select").select2({
- ajax: {
- url: "http://example.org/api/test",
- cache: "true"
- }
-});
-
-
-
- The value of the option is subject to jQuery's
- parsing rules for
- HTML5 data attributes.
-
-
-
- AMD compatibility
-
-
-
- You can find more information on how to integrate Select2 with your
- existing AMD-based project by
- viewing the 4.0 release notes .
- Select2 automatically loads some modules when the adapters are being
- automatically constructed, so those who are using Select2 with a custom
- AMD build using their own system may need to specify the paths that are
- generated to the Select2 modules.
-
-
-
-
-
- Key
-
- amdBase
-
-
- Default
-
- select2/
-
-
-
-
-
- Key
-
- amdLanguageBase
-
-
- Default
-
- select2/i18n/
-
-
-
-
-
-
- Displaying selections
-
-
-
- Select2 provides options that allow you to directly affect how the
- container that holds the current selection is displayed.
-
-
-
- Placeholders
-
-
-
- Select2 can display a placeholder for a single-value select that will
- replace an option, or be shown when no options are selected for
- multiple-value selects. You can find an example on the
- example page .
-
-
-
-
-
- Key
-
- placeholder
-
-
- Value
- string or object
-
-
-
-
-
- Adapter
-
- SelectionAdapter
-
-
- Decorator
-
- Placeholder
- and
- HidePlaceholder
-
-
-
-
-
-
- Heads up!
- Because browsers assume that the first option
in
- single-value select boxes is selected, you should add an empty
- <option></option>
tag that the placeholder
- should use or it may not work.
-
-
-
-
-
- If the value is a string , the placeholder will be
- displayed when a blank option is used as the placeholder.
- The value will be the message to show to users as the
- placeholders.
-
-
-
-placeholder: "Select a repository"
-
-
-
- If the value is an object , the object should be
- compatible with Select2's internal objects. The id
should
- be the id to look for when determining if the placeholder should be
- displayed. The text
should be the placeholder to display
- when that option is selected.
-
-
-
-placeholder: {
- id: "-1",
- text: "Select a repository"
-}
-
-
-
- You should pass in an object when you are using a
- framework that creates its own placeholder option . The
- id should be the same as the value
- attribute on the option
.
-
-
-
- You can allow a selected option to be cleared back to the placeholder by
- enabling the allowClear
option.
-
-
-
-
-
- Key
- allowClear
-
- Value
- boolean
-
-
-
-
-
- Adapter
-
- SelectionAdapter
-
-
- Decorator
-
- AllowClear
-
-
-
-
-
-
- This will display an "x" that the user can click to clear the current
- selection. It is designed to be used for cases where a single selection
- can be made.
-
-
-
- Multiple selections
-
-
-
- Select2 can display either a single selection or multiple selections.
-
-
-
- Key
- multiple
-
- Value
- boolean (true
or false
)
-
-
-
- This option will determine what the SelectAdapter
(used by
- default) should use to set the value of the underlying select
- element. It will also determine if the MultipleSelection
- adapter should be used.
-
-
-
- Container width
-
-
-
- Select2 will try to match the width of the original element as closely as
- possible. Sometimes this isn't perfect, which is what you can tell Select2
- how to determine the width.
-
-
-
-
-
-
-
- Value
- Description
-
-
-
-
- "element"
-
- Uses javascript to calculate the width of the source element.
-
-
-
- "style"
-
- Copies the value of the width style
attribute set on the source element.
-
-
-
- "resolve"
-
- Tries to use style
to determine the width, falling back to element
.
-
-
-
- Anything else
-
- The value of the width
option is directly set as the width of the container.
-
-
-
-
-
-
-
- Key
- width
-
- Value
- string
-
-
-
-
-
- Internationalization (Language support)
-
-
-
- Messages will be displayed to users when necessary, such as when no
- search results were found or more characters need to be entered in order
- for a search to be made. These messages have been
- translated into many languages
- by contributors to Select2, but you can also provide your own
- translations.
-
-
-
-
-
- Key
- language
-
- Value
- object or string
-
-
-
-
-
- Module
-
- Translation
-
-
-
-
-
-
- Heads up! When using translations provided by Select2,
- you must make sure to include the translation file in your page after
- Select2.
-
-
-
-
-
- When a string is passed in as the language, Select2 will try to resolve
- it into a language file. This allows you to specify your own language
- files, which must be defined as an AMD module. If the language file
- cannot be found, Select2 will assume it is a language code controlled by
- Select2, and it will try to load the translations for that language
- instead.
-
-
-
- You can include your own translations by providing an object similar to
- the one below.
-
-
-
-language: {
- // You can find all of the options in the language files provided in the
- // build. They all must be functions that return the string that should be
- // displayed.
- inputTooShort: function () {
- return "You must enter more characters...";
- }
-}
-
-
-
- Templating results and selections
-
-
-
- By default, Select2 will display the option text within the list of
- results and when the option has been selected. Select2 comes with options
- that allow you to further customize the display of results and selections,
- allowing you to display them however you want.
-
-
-
- Customizing the display of selections
-
-
-
- When an option is displayed after it has been selected, it is passed
- through a formatting function that determines what is displayed. By
- default, the function only returns the text
key of the data
- object.
-
-
-
- Key
- templateSelection
-
- Value
- A function taking a selection
object
-
-
-
- Anything rendered as a selection is templated.
- This includes placeholders and pre-existing selections that are displayed,
- so you must ensure that your templating functions can support them.
-
-
-
- The templateSelection
function should return a string
- containing the text to be displayed, or an object (such as a jQuery
- object) that contains the data that should be displayed.
-
-
-
- Strings are assumed to contain only text and will be
- passed through the escapeMarkup
function, which strips any
- HTML markup.
-
-
-
-
- Anything else will be passed
- directly to jQuery.fn.append
- and will be handled directly by jQuery. Any markup, such as
- HTML, returned will not be escaped and it is up to you to escape any
- malicious input provided by users.
-
-
-
- Customizing the display of results
-
-
-
- When an option is displayed after it has been selected, it is passed
- through a formatting function that determines what is displayed. By
- default, the function only returns the text
key of the data
- object.
-
-
-
- Key
- templateResult
-
- Value
- A function taking a result
object
-
-
-
- Anything rendered in the results is templated.
- This includes results such as the "Searching..." and "Loading more..."
- text which will periodically be displayed, which allows you to add more
- advanced formatting to these automatically generated options.
-
-
-
- The templateResult
function should return a string
- containing the text to be displayed, or an object (such as a jQuery
- object) that contains the data that should be displayed. It can also
- return null
, which will prevent the option from being
- displayed in the results list.
-
-
-
- Strings are assumed to contain only text and will be
- passed through the escapeMarkup
function, which strips any
- HTML markup.
-
-
-
-
- Anything else will be passed
- directly to jQuery.fn.append
- and will be handled directly by jQuery. Any markup, such as
- HTML, returned will not be escaped and it is up to you to escape any
- malicious input provided by users.
-
-
-
- Returning and displaying results
-
-
-
- Select2 can work on many different data sets ranging from local options,
- the same way that a <select>
typically works, from
- remote options where a server generates the results that users can select
- from.
-
-
-
- Array
-
-
-
- Select2 allows creating the results based on an array of data objects that
- is included when initializing Select2.
-
-
-
-
-
- Key
- data
-
- Value
- array of objects
-
-
-
-
-
- Adapter
-
- ArrayAdapter
-
-
-
-
-
-
- The objects that the users can select from should be passed as an array
- with each object containing id
and text
- properties.
-
-
-
- AJAX
-
-
-
- Select2 allows searching for results from remote data sources using AJAX
- requests.
-
-
-
-
-
- Key
- ajax
-
- Value
- object
-
-
-
-
-
- Adapter
-
- AjaxAdapter
-
-
-
-
-
-
- All options passed to this option will be directly passed to the
- $.ajax
function that executes AJAX requests. There are a few
- custom options that Select2 will intercept, allowing you to customize the
- request as it is being made.
-
-
-ajax: {
- // The number of milliseconds to wait for the user to stop typing before
- // issuing the ajax request.
- delay: 250,
- // You can craft a custom url based on the parameters that are passed into the
- // request. This is useful if you are using a framework which has
- // JavaScript-based functions for generating the urls to make requests to.
- //
- // @param params The object containing the parameters used to generate the
- // request.
- // @returns The url that the request should be made to.
- url: function (params) {
- return UrlGenerator.Random();
- },
- // You can pass custom data into the request based on the parameters used to
- // make the request. For `GET` requests, the default method, these are the
- // query parameters that are appended to the url. For `POST` requests, this
- // is the form data that will be passed into the request. For other requests,
- // the data returned from here should be customized based on what jQuery and
- // your server are expecting.
- //
- // @param params The object containing the parameters used to generate the
- // request.
- // @returns Data to be directly passed into the request.
- data: function (params) {
- var queryParameters = {
- q: params.term
- }
-
- return queryParameters;
- },
- // You can modify the results that are returned from the server, allowing you
- // to make last-minute changes to the data, or find the correct part of the
- // response to pass to Select2. Keep in mind that results should be passed as
- // an array of objects.
- //
- // @param data The data as it is returned directly by jQuery.
- // @returns An object containing the results data as well as any required
- // metadata that is used by plugins. The object should contain an array of
- // data objects as the `results` key.
- processResults: function (data) {
- return {
- results: data
- };
- },
- // You can use a custom AJAX transport function if you do not want to use the
- // default one provided by jQuery.
- //
- // @param params The object containing the parameters used to generate the
- // request.
- // @param success A callback function that takes `data`, the results from the
- // request.
- // @param failure A callback function that indicates that the request could
- // not be completed.
- // @returns An object that has an `abort` function that can be called to abort
- // the request if needed.
- transport: function (params, success, failure) {
- var $request = $.ajax(params);
-
- $request.then(success);
- $request.fail(failure);
-
- return $request;
- }
-}
-
-
-
-
-
-
- Users can create their own options based on the text that they have
- entered.
-
-
-
-
-
- Key
- tags
-
- Value
- boolean / array of objects
-
-
-
-
-
- Adapter
-
- DataAdapter
-
-
- Decorator
-
- Tags
-
-
-
-
-
-
- If the tags
option is passed into Select2, if a user types
- anything into the search box which doesn't already exist, it will be
- displayed at the top and the user will be able to select it.
-
-
-
- For backwards compatibility , if an array of objects is
- passed in with the tags
option, the options will be
- automatically created and the user will be able to select from them.
- This is the same as how array data
- works , and has similar limitations.
-
-
-
- Change how options are matched when searching
-
-
-
- When users filter down the results by entering search terms into the
- search box, Select2 uses an internal "matcher" to match search terms to
- results. When a remote data set is used, Select2 expects that the
- returned results have already been filtered.
-
-
-
- Key
-
- matcher
-
-
- Value
-
- A function taking search params
and the
- data
object.
-
-
-
-
- Select2 will pass the individual data objects that have been passed back
- from the data adapter into the matcher
individually to
- determine if they should be displayed. Only the first-level objects will
- be passed in, so if you are working with nested data, you need to
- match those individually .
-
-
-
-matcher: function (params, data) {
- // If there are no search terms, return all of the data
- if ($.trim(params.term) === '') {
- return data;
- }
-
- // `params.term` should be the term that is used for searching
- // `data.text` is the text that is displayed for the data object
- if (data.text.indexOf(params.term) > -1) {
- var modifiedData = $.extend({}, data, true);
- modifiedData.text += ' (matched)';
-
- // You can return modified objects from here
- // This includes matching the `children` how you want in nested data sets
- return modifiedData;
- }
-
- // Return `null` if the term should not be displayed
- return null;
-}
-
-
-
- This allows for more advanced matching when working with nested objects,
- allowing you to handle them however you want. For those who are not
- looking to implement highly customized matching, but instead are just
- looking to change the matching algorithm for the text, a
- compatibility modules has been created to
- make it easier.
-
-
diff --git a/pages/12.advanced/dropdown.html b/pages/12.advanced/dropdown.html
deleted file mode 100644
index 87629077..00000000
--- a/pages/12.advanced/dropdown.html
+++ /dev/null
@@ -1,308 +0,0 @@
-
-
-
-
- Select2 allows you to change the way that the dropdown works, allowing you
- to do anything from attach it to a different location in the document or
- add a search box.
-
-
-
- Attached to body
-
-
-
- By default, Select2 will attach the dropdown to the end of the body and
- will absolutely position it to appear below the selection container.
-
-
-
-
-
- Key
- dropdownParent
-
- Value
- jQuery element or DOM node
-
-
-
- Adapter
-
- DropdownAdapter
-
-
- Decorator
-
- AttachBody
-
-
-
-
-
-
- Heads up!
- This will cause DOM events to be raised outside of the standard
- Select2 DOM container. This can cause issues with
- third-party components such as modals.
-
-
-
-
-
- When the dropdown is attached to the body, you are not limited to just
- displaying the dropdown below the container. Select2 will display above
- the container if there is not enough space below the container, but there
- is enough space above it. You are also not limited to displaying the
- dropdown within the parent container, which means Select2 will render
- correctly inside of modals and other small containers.
-
-
-
- Attached below the container
-
-
-
- Select2 can place the dropdown directly after the selection container, so
- it will appear in the same location within the DOM as the rest of Select2.
-
-
-
-
-
- Adapter
-
- DropdownAdapter
-
-
- Decorator
-
- AttachContainer
-
-
-
-
-
-
-
Check your build. This module is only included in the
-
full builds of
- Select2.
-
-
-
-
-
-
- Harvest Chosen
- migrators!
-
- If you are migrating to Select2 from Chosen, this option will cause
- Select2 to position the dropdown in a similar way.
-
-
-
- Search
-
-
-
- Users can filter down the results by typing a search term into a box that
- is displayed at the top of the dropdown.
-
-
-
- Adapter
-
- DropdownAdapter
-
-
- Decorator
-
- DropdownSearch
-
-
-
-
- A search box is added to the top of the dropdown automatically for select
- boxes where only a single option can be selected.
-
-
-
-
-
- Sometimes when working with large data sets, it is more efficient to start
- filtering the results when the search term is a certain length. This is
- very common when working with remote data sets, as allows for only
- significant search terms to be used.
-
-
-
-
-
- Key
- minimumInputLength
-
- Value
- integer
-
-
-
-
-
- Adapter
-
- DataAdapter
-
-
- Decorator
-
- MinimumInputLength
-
-
-
-
-
-
-
-
- In some cases, search terms need to be limited to a certain range. Select2
- allows you to limit the length of the search term such that it does not
- exceed a certain length.
-
-
-
-
-
- Key
- maximumInputLength
-
- Value
- integer
-
-
-
-
-
- Adapter
-
- DataAdapter
-
-
- Decorator
-
- MaximumInputLength
-
-
-
-
-
-
-
-
- When working with smaller data sets, the search box can take up more space
- that is necessary, as there are not enough results for filtering to be
- effective. Select2 allows you to only display the search box when the
- number of search results reaches a certain threshold.
-
-
-
-
-
- Key
- minimumResultsForSearch
-
- Value
- integer
-
-
-
-
-
- Adapter
-
- DropdownAdapter
-
-
- Decorator
-
- MinimumResultsForSearch
-
-
-
-
-
-
- Select the highlighted option on close
-
-
-
- When users close the dropdown, the last highlighted option can be
- automatically selected. This is commonly used in combination with
- tagging and placeholders
- and other situations where the user is required to select an option, or
- they need to be able to quickly select multiple options.
-
-
-
- Adapter
-
- ResultsAdapter
-
-
- Decorator
-
- SelectOnClose
-
-
-
-
- Close the dropdown when a result is selected
-
-
-
- Select2 will automatically close the dropdown when an element is selected,
- similar to what is done with a normal select box. This behavior can be
- changed though to keep the dropdown open when results are selected,
- allowing for multiple options to be selected quickly.
-
-
-
-
-
- Key
- closeOnSelect
-
- Default
- true
-
-
-
-
-
- Adapter
-
- DropdownAdapter
-
-
- Decorator
-
- CloseOnSelect
-
-
-
-
-
-
- If this decorator is not used (or closeOnSelect
is set to
- false
), the dropdown will not automatically close when a
- result is selected. The dropdown will also never close if the
- ctrl key is held down when the result is selected.
-
-
diff --git a/pages/12.advanced/setting-default-options.html b/pages/12.advanced/setting-default-options.html
deleted file mode 100644
index f2c74f60..00000000
--- a/pages/12.advanced/setting-default-options.html
+++ /dev/null
@@ -1,37 +0,0 @@
-
- Setting default options
-
-
- In some cases, you need to set the default options for all instances of
- Select2 in your web application. This is especially useful when you are
- migrating from past versions of Select2, or you are using non-standard
- options like custom AMD builds . Select2 exposes the
- default options through $.fn.select2.defaults
, which allows
- you to set them globally.
-
-
-
- When setting options globally, any past defaults that have been set will
- be overriden. Default options are only used when an option is requested
- that has not been set during initialization.
-
-
-
- You can set default options by calling
- $.fn.select2.defaults.set("key", "value")
. The key that is
- set should take the same format as keys set using
- HTML data-*
attributes which
- means that two dashes (--
) will be replaced by a level of
- nesting, and a single dash (-
) will convert it to a camelCase
- string.
-
-
-
-$.fn.select2.defaults.set("theme", "classic");
-
-
-
- You can reset the default options by calling
- $.fn.select2.defaults.reset()
.
-
-
diff --git a/pages/11.i18n/docs.md b/pages/12.i18n/docs.md
similarity index 61%
rename from pages/11.i18n/docs.md
rename to pages/12.i18n/docs.md
index 034d7d4d..6c65c5dc 100644
--- a/pages/11.i18n/docs.md
+++ b/pages/12.i18n/docs.md
@@ -9,11 +9,15 @@ never_cache_twig: true
{% do assets.addJs('https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n/es.js', 90) %}
-## Multiple languages (localization)
+## Message translations
-Select2 can load message translations for different languages from language files.
+When necessary, Select2 displays certain messages to the user. For example, a message will appear when no search results were found or more characters need to be entered in order for a search to be made. These messages have been translated into many languages by contributors to Select2, but you can also provide your own translations.
-The language does not have to be defined when Select2 is being initialized, but instead can be defined in the `[lang]` attribute of any parent elements as `[lang="es"]`.
+### Language files
+
+Select2 can load message translations for different languages from language files. When using translations provided by Select2, you must make sure to include the translation file in your page after Select2.
+
+When a string is passed in as the language, Select2 will try to resolve it into a language file. This allows you to specify your own language files, which must be defined as an AMD module. If the language file cannot be found, Select2 will assume it is is one of Select2's built-in languages, and it will try to load the translations for that language instead.
@@ -34,8 +38,24 @@ $(".js-example-language").select2({
});
-You may alternatively provide your own custom messages to be displayed.
+The language does not have to be defined when Select2 is being initialized, but instead can be defined in the `[lang]` attribute of any parent elements as `[lang="es"]`.
+### Translation objects
+
+You may alternatively provide your own custom messages to be displayed by providing an object similar to the one below:
+
+```
+language: {
+ // You can find all of the options in the language files provided in the
+ // build. They all must be functions that return the string that should be
+ // displayed.
+ inputTooShort: function () {
+ return "You must enter more characters...";
+ }
+}
+```
+
+>>> Translations are handled by the `select2/translation` module.
## RTL support
diff --git a/pages/13.advanced/01.adapters-and-decorators/docs.md b/pages/13.advanced/01.adapters-and-decorators/docs.md
new file mode 100644
index 00000000..9bc4df92
--- /dev/null
+++ b/pages/13.advanced/01.adapters-and-decorators/docs.md
@@ -0,0 +1,130 @@
+---
+title: Adapters and Decorators
+taxonomy:
+ category: docs
+---
+
+Starting in version 4.0, Select2 uses the [Adapter pattern](https://en.wikipedia.org/wiki/Adapter_pattern) as a powerful means of extending its features and behavior.
+
+Most of the built-in features, such as those described in the previous chapters, are implemented via one of the [built-in adapters](/default-adapters). You may further extend the functionality of Select2 by implementing your own adapters.
+
+## Adapter interfaces
+
+All custom adapters must implement the methods described by the `Adapter` interface.
+
+In addition, adapters that override the default `selectionAdapter` and `dataAdapter` behavior must implement the additional methods described by the corresponding `SelectionAdapter` and `DataAdapter` interfaces.
+
+### `Adapter`
+
+All adapters must implement the `Adapter` interface, which Select2 uses to render DOM elements for the adapter and bind any internal events:
+
+```
+// The basic HTML that should be rendered by Select2. A jQuery or DOM element
+// should be returned, which will automatically be placed by Select2 within the
+// DOM.
+//
+// @returns A jQuery or DOM element that contains any elements that must be
+// rendered by Select2.
+Adapter.render = function () {
+ return $jq;
+};
+
+// Bind to any Select2 or DOM events.
+//
+// @param container The Select2 object that is bound to the jQuery element. You
+// can listen to Select2 events with `on` and trigger Select2 events using the
+// `trigger` method.
+// @param $container The jQuery DOM node that all default adapters will be
+// rendered within.
+Adapter.bind = function (container, $container) { };
+
+// Position the DOM element within the Select2 DOM container, or in another
+// place. This allows adapters to be located outside of the Select2 DOM,
+// such as at the end of the document or in a specific place within the Select2
+// DOM node.
+//
+// Note: This method is not called on data adapters.
+//
+// @param $rendered The rendered DOM element that was returned from the call to
+// `render`. This may have been modified by Select2, but the root element
+// will always be the same.
+// @param $defaultContainer The default container that Select2 will typically
+// place the rendered DOM element within. For most adapters, this is the
+// Select2 DOM element.
+Adapter.position = function ($rendered, $defaultContainer) { };
+
+// Destroy any events or DOM elements that have been created.
+// This is called when `select2("destroy")` is called on an element.
+Adapter.destroy = function () { };
+```
+
+### `SelectionAdapter`
+
+The selection is what is shown to the user as a replacement of the standard `` box. It controls the display of the selection option(s), as well anything else that needs to be embedded within the container, such as a search box.
+
+Adapters that will be used to override the default `selectionAdapter` must implement the `update` method as well:
+
+```
+// Update the selected data.
+//
+// @param data An array of data objects that have been generated by the data
+// adapter. If no objects should be selected, an empty array will be passed.
+//
+// Note: An array will always be passed into this method, even if Select2 is
+// attached to a source which only accepts a single selection.
+SelectionAdapter.update = function (data) { };
+```
+
+### `DataAdapter`
+
+The data set is what Select2 uses to generate the possible results that can be selected, as well as the currently selected results.
+
+Adapters that will be used to override the default `dataAdapter` must implement the `current` and `query` methods as well:
+
+```
+// Get the currently selected options. This is called when trying to get the
+// initial selection for Select2, as well as when Select2 needs to determine
+// what options within the results are selected.
+//
+// @param callback A function that should be called when the current selection
+// has been retrieved. The first parameter to the function should be an array
+// of data objects.
+DataAdapter.current = function (callback) {
+ callback(currentData);
+}
+
+// Get a set of options that are filtered based on the parameters that have
+// been passed on in.
+//
+// @param params An object containing any number of parameters that the query
+// could be affected by. Only the core parameters will be documented.
+// @param params.term A user-supplied term. This is typically the value of the
+// search box, if one exists, but can also be an empty string or null value.
+// @param params.page The specific page that should be loaded. This is typically
+// provided when working with remote data sets, which rely on pagination to
+// determine what objects should be displayed.
+// @param callback The function that should be called with the queried results.
+DataAdapter.query = function (params, callback) {
+ callback(queryiedData);
+}
+```
+
+## Decorators
+
+Select2 uses [decorators](https://en.wikipedia.org/wiki/Decorator_pattern) to expose the functionality of adapters through its [configuration options](/configuration).
+
+You can apply a decorator to an adapter using the `Utils.Decorate` method provided with Select2:
+
+```
+$.fn.select2.amd.require(
+ ["select2/utils", "select2/selection/single", "select2/selection/placeholder"],
+ function (Utils, SingleSelection, Placeholder) {
+ var CustomSelectionAdapter = Utils.Decorate(SingleSelection, Placeholder);
+});
+```
+
+>>> All core options that use decorators or adapters will clearly state it in the "Decorator" or "Adapter" part of the documentation. Decorators are typically only compatible with a specific type of adapter, so make sure to note what adapter is given.
+
+## AMD Compatibility
+
+You can find more information on how to integrate Select2 with your existing AMD-based project by viewing the 4.0 release notes . Select2 automatically loads some modules when the adapters are being automatically constructed, so those who are using Select2 with a custom AMD build using their own system may need to specify the paths that are generated to the Select2 modules.
diff --git a/pages/13.advanced/02.default-adapters/01.selection/docs.md b/pages/13.advanced/02.default-adapters/01.selection/docs.md
new file mode 100644
index 00000000..6caad0b0
--- /dev/null
+++ b/pages/13.advanced/02.default-adapters/01.selection/docs.md
@@ -0,0 +1,39 @@
+---
+title: Selection
+taxonomy:
+ category: docs
+---
+
+Select2 provides the `SingleSelection` and `MultipleSelection` adapters as default implementations of the `SelectionAdapter` for single- and multi-select controls, respectively. Both `SingleSelection` and `MultipleSelection` extend the base `BaseSelection` adapter.
+
+The selection adapter can be overridden by assigning a custom adapter to the `selectionAdapter` configuration option.
+
+`select2/selection`
+
+## Decorators
+
+### `Placeholder` and `HidePlaceholder`
+
+**AMD Modules:**
+
+`select2/selection/placeholder`
+`select2/dropdown/hidePlaceholder`
+
+These decorators implement Select2's [placeholder](/placeholders) features.
+
+
+### `AllowClear`
+
+**AMD Modules:**
+
+`select2/selection/allowClear`
+
+This decorator implements [clearable selections](/selections#clearable-selections) as exposed through the `allowClear` option.
+
+### `EventRelay`
+
+**AMD Modules:**
+
+`select2/selection/eventRelay`
+
+Select2 has an internal event system that is used to notify parts of the component that state has changed, as well as an adapter that allows some of these events to be relayed to the outside word.
diff --git a/pages/13.advanced/02.default-adapters/02.array/docs.md b/pages/13.advanced/02.default-adapters/02.array/docs.md
new file mode 100644
index 00000000..e03453fd
--- /dev/null
+++ b/pages/13.advanced/02.default-adapters/02.array/docs.md
@@ -0,0 +1,49 @@
+---
+title: Array
+taxonomy:
+ category: docs
+---
+
+
+
+
+ Array
+
+
+
+ Select2 allows creating the results based on an array of data objects that
+ is included when initializing Select2.
+
+
+
+
+
+ Key
+ data
+
+ Value
+ array of objects
+
+
+
+
+
+ Adapter
+
+ ArrayAdapter
+
+
+
+
+
+
+ The objects that the users can select from should be passed as an array
+ with each object containing id
and text
+ properties.
+
+
+Select2 provides the `SingleSelection` and `MultipleSelection` adapters as default implementations of the `SelectionAdapter` for single- and multi-select controls, respectively. Both `SingleSelection` and `MultipleSelection` extend the base `BaseSelection` adapter.
+
+The selection adapter can be overridden by assigning a custom adapter to the `selectionAdapter` configuration option.
+
+## Decorators
\ No newline at end of file
diff --git a/pages/13.advanced/02.default-adapters/03.ajax/docs.md b/pages/13.advanced/02.default-adapters/03.ajax/docs.md
new file mode 100644
index 00000000..7a105935
--- /dev/null
+++ b/pages/13.advanced/02.default-adapters/03.ajax/docs.md
@@ -0,0 +1,118 @@
+---
+title: Ajax
+taxonomy:
+ category: docs
+---
+
+
+
+ AJAX
+
+
+
+ Select2 allows searching for results from remote data sources using AJAX
+ requests.
+
+
+
+
+
+ Key
+ ajax
+
+ Value
+ object
+
+
+
+
+
+ Adapter
+
+ AjaxAdapter
+
+
+
+
+
+
+ All options passed to this option will be directly passed to the
+ $.ajax
function that executes AJAX requests. There are a few
+ custom options that Select2 will intercept, allowing you to customize the
+ request as it is being made.
+
+
+ajax: {
+ // The number of milliseconds to wait for the user to stop typing before
+ // issuing the ajax request.
+ delay: 250,
+ // You can craft a custom url based on the parameters that are passed into the
+ // request. This is useful if you are using a framework which has
+ // JavaScript-based functions for generating the urls to make requests to.
+ //
+ // @param params The object containing the parameters used to generate the
+ // request.
+ // @returns The url that the request should be made to.
+ url: function (params) {
+ return UrlGenerator.Random();
+ },
+ // You can pass custom data into the request based on the parameters used to
+ // make the request. For `GET` requests, the default method, these are the
+ // query parameters that are appended to the url. For `POST` requests, this
+ // is the form data that will be passed into the request. For other requests,
+ // the data returned from here should be customized based on what jQuery and
+ // your server are expecting.
+ //
+ // @param params The object containing the parameters used to generate the
+ // request.
+ // @returns Data to be directly passed into the request.
+ data: function (params) {
+ var queryParameters = {
+ q: params.term
+ }
+
+ return queryParameters;
+ },
+ // You can modify the results that are returned from the server, allowing you
+ // to make last-minute changes to the data, or find the correct part of the
+ // response to pass to Select2. Keep in mind that results should be passed as
+ // an array of objects.
+ //
+ // @param data The data as it is returned directly by jQuery.
+ // @returns An object containing the results data as well as any required
+ // metadata that is used by plugins. The object should contain an array of
+ // data objects as the `results` key.
+ processResults: function (data) {
+ return {
+ results: data
+ };
+ },
+ // You can use a custom AJAX transport function if you do not want to use the
+ // default one provided by jQuery.
+ //
+ // @param params The object containing the parameters used to generate the
+ // request.
+ // @param success A callback function that takes `data`, the results from the
+ // request.
+ // @param failure A callback function that indicates that the request could
+ // not be completed.
+ // @returns An object that has an `abort` function that can be called to abort
+ // the request if needed.
+ transport: function (params, success, failure) {
+ var $request = $.ajax(params);
+
+ $request.then(success);
+ $request.fail(failure);
+
+ return $request;
+ }
+}
+
+
+
+
+Select2 provides the `SingleSelection` and `MultipleSelection` adapters as default implementations of the `SelectionAdapter` for single- and multi-select controls, respectively. Both `SingleSelection` and `MultipleSelection` extend the base `BaseSelection` adapter.
+
+The selection adapter can be overridden by assigning a custom adapter to the `selectionAdapter` configuration option.
+
+## Decorators
\ No newline at end of file
diff --git a/pages/13.advanced/02.default-adapters/04.data/docs.md b/pages/13.advanced/02.default-adapters/04.data/docs.md
new file mode 100644
index 00000000..651cb111
--- /dev/null
+++ b/pages/13.advanced/02.default-adapters/04.data/docs.md
@@ -0,0 +1,48 @@
+---
+title: SelectAdapter
+taxonomy:
+ category: docs
+---
+
+Select2 provides the `SelectAdapter` as a default implementation of the `DataAdapter` adapter. It extends `BaseAdapter`.
+
+This adapter can be overridden by assigning a custom adapter to the `dataAdapter` configuration option.
+
+**AMD Modules:**
+
+- `select2/data/base`
+- `select2/data/select`
+
+## Decorators
+
+### `Tags`
+
+This decorator implements the [tagging](/tagging) feature.
+
+**AMD Modules:**
+
+`select2/data/tags`
+
+
+ For backwards compatibility , if an array of objects is
+ passed in with the tags
option, the options will be
+ automatically created and the user will be able to select from them.
+ This is the same as how array data
+ works , and has similar limitations.
+
+
+### `MinimumInputLength`
+
+This decorator implements the [minimum search term length](/searching#minimum-search-term-length) feature as exposed through the `minimumInputLength` configuration option.
+
+**AMD Modules:**
+
+`select2/data/minimumInputLength`
+
+### `MaximumInputLength`
+
+This decorator implements the [maximum search term length](/searching#maximum-search-term-length) feature as exposed through the `maximumInputLength` configuration option.
+
+**AMD Modules:**
+
+`select2/data/maximumInputLength`
diff --git a/pages/13.advanced/02.default-adapters/05.results/docs.md b/pages/13.advanced/02.default-adapters/05.results/docs.md
new file mode 100644
index 00000000..25384baa
--- /dev/null
+++ b/pages/13.advanced/02.default-adapters/05.results/docs.md
@@ -0,0 +1,31 @@
+---
+title: Results
+taxonomy:
+ category: docs
+---
+
+The `ResultsAdapter` controls the list of results that the user can select from.
+
+The results adapter can be overridden by assigning a custom adapter to the `resultsAdapter` configuration option. While the results adapter does not define any additional methods that must be implemented, it makes extensive use of the Select2 event system for controlling the display of results and messages.
+
+**AMD Modules:**
+
+`select2/results`
+
+## Decorators
+
+### `Tags`
+
+This decorator implements the [tagging](/tagging) feature.
+
+**AMD Modules:**
+
+`select2/data/tags`
+
+### `SelectOnClose`
+
+This decorator implements [automatic selection](/dropdown#automatic-selection) of the highlighted option when the dropdown is closed.
+
+**AMD Modules:**
+
+`select2/dropdown/selectOnClose`
diff --git a/pages/13.advanced/02.default-adapters/06.dropdown/docs.md b/pages/13.advanced/02.default-adapters/06.dropdown/docs.md
new file mode 100644
index 00000000..099d987f
--- /dev/null
+++ b/pages/13.advanced/02.default-adapters/06.dropdown/docs.md
@@ -0,0 +1,157 @@
+---
+title: Dropdown
+taxonomy:
+ category: docs
+---
+
+The dropdown adapter defines the main container that the dropdown should be held in. Select2 allows you to change the way that the dropdown works, allowing you to do anything from attach it to a different location in the document or add a search box.
+
+It is common for decorators to attach to the `render` and `position` methods to alter how the dropdown is altered and positioned.
+
+This adapter can be overridden by assigning a custom adapter to the `dropdownAdapter` configuration option.
+
+`select2/dropdown`
+
+## Decorators
+
+### `AttachBody`
+
+By default, Select2 will attach the dropdown to the end of the body and will absolutely position it to appear below the selection container.
+
+`select2/dropdown/attachBody`
+
+
+ Attached to body
+
+
+
+
+
+ Heads up!
+ This will cause DOM events to be raised outside of the standard
+ Select2 DOM container. This can cause issues with
+ third-party components such as modals.
+
+
+
+
+
+ When the dropdown is attached to the body, you are not limited to just
+ displaying the dropdown below the container. Select2 will display above
+ the container if there is not enough space below the container, but there
+ is enough space above it. You are also not limited to displaying the
+ dropdown within the parent container, which means Select2 will render
+ correctly inside of modals and other small containers.
+
+
+### `AttachContainer`
+
+`select2/dropdown/attachContainer`
+
+
+ Attached below the container
+
+
+
+ Select2 can place the dropdown directly after the selection container, so
+ it will appear in the same location within the DOM as the rest of Select2.
+
+
+
+
+
+
+
Check your build. This module is only included in the
+
full builds of
+ Select2.
+
+
+
+
+
+
+ Harvest Chosen
+ migrators!
+
+ If you are migrating to Select2 from Chosen, this option will cause
+ Select2 to position the dropdown in a similar way.
+
+
+### `DropdownSearch`
+
+`select2/dropdown/search`
+
+
+ Users can filter down the results by typing a search term into a box that
+ is displayed at the top of the dropdown.
+
+
+
+ A search box is added to the top of the dropdown automatically for select
+ boxes where only a single option can be selected.
+
+
+### `MinimumResultsForSearch`
+
+`select2/dropdown/minimumResultsForSearch`
+
+
+
+
+ When working with smaller data sets, the search box can take up more space
+ that is necessary, as there are not enough results for filtering to be
+ effective. Select2 allows you to only display the search box when the
+ number of search results reaches a certain threshold.
+
+
+
+
+
+ Key
+ minimumResultsForSearch
+
+ Value
+ integer
+
+
+
+
+
+### `CloseOnSelect`
+
+`select2/dropdown/closeOnSelect`
+
+
+ Close the dropdown when a result is selected
+
+
+
+ Select2 will automatically close the dropdown when an element is selected,
+ similar to what is done with a normal select box. This behavior can be
+ changed though to keep the dropdown open when results are selected,
+ allowing for multiple options to be selected quickly.
+
+
+
+
+
+ Key
+ closeOnSelect
+
+ Default
+ true
+
+
+
+
+
+
+
+ If this decorator is not used (or closeOnSelect
is set to
+ false
), the dropdown will not automatically close when a
+ result is selected. The dropdown will also never close if the
+ ctrl key is held down when the result is selected.
+
+
diff --git a/pages/13.advanced/02.default-adapters/docs.md b/pages/13.advanced/02.default-adapters/docs.md
new file mode 100644
index 00000000..f47e5123
--- /dev/null
+++ b/pages/13.advanced/02.default-adapters/docs.md
@@ -0,0 +1,7 @@
+---
+title: Built-in adapters
+taxonomy:
+ category: docs
+---
+
+This section describes the built-in adapters for Select2, as well as the decorators they use to expose their functionality.
diff --git a/pages/12.advanced/announcements-4.0.html b/pages/13.advanced/announcements-4.0.html
similarity index 100%
rename from pages/12.advanced/announcements-4.0.html
rename to pages/13.advanced/announcements-4.0.html
diff --git a/pages/12.advanced/backwards-compatibility.html b/pages/13.advanced/backwards-compatibility.html
similarity index 87%
rename from pages/12.advanced/backwards-compatibility.html
rename to pages/13.advanced/backwards-compatibility.html
index 4bdd9372..8b56a0e6 100644
--- a/pages/12.advanced/backwards-compatibility.html
+++ b/pages/13.advanced/backwards-compatibility.html
@@ -1,3 +1,34 @@
+
+
+
+### Compatibility module for Select2 v3.5
+
+This custom matcher uses a [compatibility module](/configuration/deprecated) that is only bundled in the [full version of Select2](/getting-started/builds). You also have the option of using a more complex matcher .
+
+
+
+
+
+
+
+
+