- You can, and should, use a <label> with Select2, just like any other <select> element.
-
-
-
-
-
-
-
-
-
-
-
-{% highlight html linenos %}
-
-
-
-{% endhighlight %}
-
\ No newline at end of file
diff --git a/docs/_includes/examples/data.html b/docs/_includes/examples/data.html
deleted file mode 100644
index 4b55a760..00000000
--- a/docs/_includes/examples/data.html
+++ /dev/null
@@ -1,123 +0,0 @@
-
-
-
- Data sources
-
-
-
In addition to handling options from a standard <select>, Select2 can also retrieve the results from other data sources.
-
-
Loading array data
-
-
- Select2 provides a way to load the data from a local array.
- You can provide initial selections with array data by providing the
- option tag for the selected values, similar to how it would be done for
- a standard select.
-
- Select2 comes with AJAX support built in, using jQuery's AJAX methods.
- In this example, we can search for repositories using GitHub's API.
-
-
-
-
-
-
-
- When using Select2 with remote data, the HTML required for the
- select is the same as any other Select2. If you need to
- provide default selections, you just need to include an
- option for each selection that contains the value and text
- that should be displayed.
-
- You can configure how Select2 searches for remote data using the
- ajax option. More information on the individual options
- that Select2 handles can be found in the
- options documentation for ajax.
-
-
-{% highlight js linenos %}
-$(".js-data-example-ajax").select2({
- ajax: {
- url: "https://api.github.com/search/repositories",
- dataType: 'json',
- delay: 250,
- data: function (params) {
- return {
- q: params.term, // search term
- page: params.page
- };
- },
- processResults: function (data, params) {
- // parse the results into the format expected by Select2
- // since we are using custom formatting functions we do not need to
- // alter the remote JSON data, except to indicate that infinite
- // scrolling can be used
- params.page = params.page || 1;
-
- return {
- results: data.items,
- pagination: {
- more: (params.page * 30) < data.total_count
- }
- };
- },
- cache: true
- },
- escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
- minimumInputLength: 1,
- templateResult: formatRepo, // omitted for brevity, see the source of this page
- templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
-});
-{% endhighlight %}
-
-
- Select2 will pass any options in the ajax object to
- jQuery's $.ajax function, or the transport
- function you specify.
-
- Select2 will respond to the disabled attribute on
- <select> elements. You can also initialize Select2
- with disabled: true to get the same effect.
-
- Select2 will correctly handle disabled results, both with data coming
- from a standard select (when the disabled attribute is set)
- and from remote sources, where the object has
- disabled: true set.
-
- 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.
-
- Select2 supports displaying the messages in different languages, as well
- as providing your own
- custom messages
- that can 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"].
-
- Select2 will work on RTL websites if the dir attribute is
- set on the <select> or any parents of it. You can also
- initialize Select2 with dir: "rtl" set.
-
- Select2's default matcher will ignore diacritics, making it easier for
- users to filter results in international selects. Type "aero" into the
- select below.
-
- Select2 multi-value select boxes can set restrictions regarding the
- maximum number of options selected. The select below is declared with
- the multiple attribute with maximumSelectionLength
- in the select2 options.
-
- A placeholder value can be defined and will be displayed until a
- selection is made. Select2 uses the placeholder attribute
- on multiple select boxes, which requires IE 10+. You can support it in
- older versions with
- the Placeholders.js polyfill.
-
- Select2 will trigger some events on the original select element,
- allowing you to integrate it with other components. You can find more
- information on events
- on the options page.
-
-
-
- change is fired whenever an option is selected or removed.
-
-
-
- select2:open is fired whenever the dropdown is opened.
- select2:opening is fired before this and can be prevented.
-
-
-
- select2:close is fired whenever the dropdown is closed.
- select2:closing is fired before this and can be prevented.
-
-
-
- select2:select is fired whenever a result is selected.
- select2:selecting is fired before this and can be prevented.
-
-
-
- select2:unselect is fired whenever a result is unselected.
- select2:unselecting is fired before this and can be prevented.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Programmatic access
-
-
- Select2 supports methods that allow programmatic control of the
- component.
-
- In addition to the dropdown menu of options, Select2 can also allow free-text responses. This feature is called "tagging". To enable free-text responses, set the tags option to true:
-
- Note that when tagging is enabled the user can select from the pre-existing options or create a new option by picking the first choice, which is what the user has typed into the search box so far.
-
-
-
Tagging with multi-value select boxes
-
-
- Tagging can also be used in multi-value select boxes. In the example below, we set the multiple="multiple" attribute on a Select2 control that also has tags: true enabled:
-
-
-
-
-
-
-
-
-
- Try entering a value that isn't listed in the dropdown - you'll be able to add it as a new option!
-
- Various display options of the Select2 component can be changed:
- You can access the <option> element
- (or <optgroup>) and any attributes on those elements
- using .element.
-
- Select2's width can be set to a percentage of its parent to support
- responsive design. The two Select2 boxes below are styled to 50% and 75%
- width respectively.
-
- Select2 will do its best to resolve the percent width specified via a
- CSS class, but it is not always possible. The best way to ensure that
- Select2 is using a percent based width is to inline the
- style declaration into the tag.
-
- Select2 supports ability to add choices automatically as the user is
- typing into the search field. Try typing in the search field below and
- entering a space or a comma.
-
-
-
- The separators that should be used when tokenizing can be specified
- using the tokenSeparators
- options.
-
- 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.
-
- Select2 offers limited backwards compatibility with the previously 3.5.x
- release line, allowing people more efficiently transfer across releases
- and get the latest features. For many of the larger changes, such as the
- change in how custom data adapters work, compatibility modules were
- created that will be used to assist in the upgrade process. It is not
- recommended to rely on these compatibility modules, as they will not
- always exist, but they make upgrading easier for major changes.
-
-
-
- The compatibility modules are only included in the
- full builds of
- Select2. These files end in .full.js, and the
- compatibility modules are prefixed with select2/compat.
-
-
-
- Simplified function for matching data objects
-
-
-
- Added in Select2 4.0.0.
- This method was added to make upgrading easier from earlier versions of
- Select2.
-
-
-
- During the Select2 4.0.0 release, the
- matcher function was changed to allow for more complex
- matching of nested objects.
-
-
-
-
-
-
Key
-
- matcher
-
-
-
Value
-
- A function taking a search term and the data object
- text.
-
-
-
-
-
-
-
Adapter
-
- oldMatcher
-
-
-
-
-
-
- The custom matcher example provides a
- guide for how to use this in your own application. For those upgrading
- from older versions of Select2, you just need to wrap your old
- matcher with this function to maintain compatibility.
-
- In the past, Select2 required an option called initSelection
- that was defined whenever a custom data source was being used, allowing
- for the initial selection for the component to be determined. This has
- been replaced by the current method on the
- data adapter.
-
- In the past, Select2 supported an option called query that
- allowed for a custom data source to be used. This option has been replaced
- by the query method on the
- data adapter and takes a very similar set of
- parameters.
-
-
-
-
-
-
Key
-
- query
-
-
-
Value
-
- A function taking params (including a callback)
-
- In past versions of Select2, a <select> element could
- only be used with a limited subset of options. An
- <input type="hidden" /> was required instead, which did
- not allow for a graceful fallback for users who did not have JavaScript
- enabled. Select2 now supports the <select> element for
- all options, so it is no longer required to use <input />
- elements with Select2.
-
- 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...
-
- 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.
-
- 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.
-
- 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;
- }
-}
-
-
-
-
- Tags
-
-
-
- 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.
-
- 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.
-
-
-
- Minimum search term length to filter results
-
-
-
- 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
-
-
-
-
-
-
- Maximum search term length to filter results
-
-
-
- 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
-
-
-
-
-
-
- Minimum results to display the search box
-
-
-
- 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.
-
- 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.
-
-
-
-
Adapter
-
- SelectionAdapter
-
-
-
Decorator
-
- EventRelay
-
-
-
-
- Public events
-
-
-
- All public events are relayed using the jQuery event system, and they are
- triggered on the <select> element that Select2 is
- attached to. You can attach to them using the
- .on method provided
- by jQuery.
-
-
-
- Internal events
-
-
-
- Select2 triggers internal events using its own internal event system,
- which allows adapters to communicate with each other. These events are not
- accessible through the jQuery event system.
-
- 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().
-
- In the past, Select2 required an option called initSelection
- that was defined whenever a custom data source was being used, allowing
- for the initial selection for the component to be determined. This has
- been replaced by the current method on the
- data adapter.
-
-
-
-
-
-
Key
-
- initSelection
-
-
-
Value
-
- A function taking a callback
-
-
-
-
-
-
-
Adapter
-
- DataAdapter
-
-
-
Decorator
-
- InitSelection
-
-
-
-
-
\ No newline at end of file
diff --git a/docs/_includes/options/compatibility/introduction.html b/docs/_includes/options/compatibility/introduction.html
deleted file mode 100644
index 0e82aabe..00000000
--- a/docs/_includes/options/compatibility/introduction.html
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
- Select2 offers limited backwards compatibility with the previously 3.5.x
- release line, allowing people more efficiently transfer across releases
- and get the latest features. For many of the larger changes, such as the
- change in how custom data adapters work, compatibility modules were
- created that will be used to assist in the upgrade process. It is not
- recommended to rely on these compatibility modules, as they will not
- always exist, but they make upgrading easier for major changes.
-
-
-
- The compatibility modules are only included in the
- full builds of
- Select2. These files end in .full.js, and the
- compatibility modules are prefixed with select2/compat.
-
-
\ No newline at end of file
diff --git a/docs/_includes/options/compatibility/matcher.html b/docs/_includes/options/compatibility/matcher.html
deleted file mode 100644
index 150f72c1..00000000
--- a/docs/_includes/options/compatibility/matcher.html
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
- Simplified function for matching data objects
-
-
-
- Added in Select2 4.0.0.
- This method was added to make upgrading easier from earlier versions of
- Select2.
-
-
-
- During the Select2 4.0.0 release, the
- matcher function was changed to allow for more complex
- matching of nested objects.
-
-
-
-
-
-
Key
-
- matcher
-
-
-
Value
-
- A function taking a search term and the data object
- text.
-
-
-
-
-
-
-
Adapter
-
- oldMatcher
-
-
-
-
-
-
- The custom matcher example provides a
- guide for how to use this in your own application. For those upgrading
- from older versions of Select2, you just need to wrap your old
- matcher with this function to maintain compatibility.
-
-
\ No newline at end of file
diff --git a/docs/_includes/options/compatibility/query-function.html b/docs/_includes/options/compatibility/query-function.html
deleted file mode 100644
index f5f557de..00000000
--- a/docs/_includes/options/compatibility/query-function.html
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
- In the past, Select2 supported an option called query that
- allowed for a custom data source to be used. This option has been replaced
- by the query method on the
- data adapter and takes a very similar set of
- parameters.
-
-
-
-
-
-
Key
-
- query
-
-
-
Value
-
- A function taking params (including a callback)
-
-
-
-
-
-
-
Adapter
-
- DataAdapter
-
-
-
Decorator
-
- Query
-
-
-
-
-
\ No newline at end of file
diff --git a/docs/_includes/options/compatibility/text-input.html b/docs/_includes/options/compatibility/text-input.html
deleted file mode 100644
index 4cea8c86..00000000
--- a/docs/_includes/options/compatibility/text-input.html
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
- In past versions of Select2, a <select> element could
- only be used with a limited subset of options. An
- <input type="hidden" /> was required instead, which did
- not allow for a graceful fallback for users who did not have JavaScript
- enabled. Select2 now supports the <select> element for
- all options, so it is no longer required to use <input />
- elements with Select2.
-
-
-
-
Adapter
-
- DataAdapter
-
-
-
Decorator
-
- InputData
-
-
-
\ No newline at end of file
diff --git a/docs/_includes/options/core.html b/docs/_includes/options/core.html
deleted file mode 100644
index df834804..00000000
--- a/docs/_includes/options/core.html
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
- Core options
-
-
- {% include options/core/options.html %}
- {% include options/core/data-attributes.html %}
- {% include options/core/amd-support.html %}
-
\ No newline at end of file
diff --git a/docs/_includes/options/core/amd-support.html b/docs/_includes/options/core/amd-support.html
deleted file mode 100644
index 2475b013..00000000
--- a/docs/_includes/options/core/amd-support.html
+++ /dev/null
@@ -1,46 +0,0 @@
-
-
- Can I use Select2 with my AMD or CommonJS loader?
-
-
-
- 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.
-
-
-
- How do I tell Select2 where to look for modules?
-
-
-
- For most AMD and CommonJS setups, the location of the data files used by Select2 will be automatically determined and handled without you needing to do anything.
-
-
-
- If you are using Select2 in a build environment where preexisting module names are changed during a build step, Select2 may not be able to find optional dependencies or language files. You can manually set the prefixes to use for these files using the amdBase and amdLanguageBase options.
-
- Select2 is being placed before jQuery in my JavaScript file
-
-
-
- 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.
-
-
-
- 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.
-
- Can I declare my configuration within the HTML?
-
-
-
- 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.
-
-
-
- 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...
-
- Are options with nested configurations supported?
-
-
-
- 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.
-
- The value of the option is subject to jQuery's
- parsing rules for
- HTML5 data attributes.
-
-
\ No newline at end of file
diff --git a/docs/_includes/options/core/options.html b/docs/_includes/options/core/options.html
deleted file mode 100644
index 5ff3f44d..00000000
--- a/docs/_includes/options/core/options.html
+++ /dev/null
@@ -1,80 +0,0 @@
-
-
- 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.
-
- 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 overridden. 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").
-
- How can I set a default value for a nested option?
-
-
-
- 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.
-
-
- {% include options/data/select.html %}
- {% include options/data/array.html %}
- {% include options/data/ajax.html %}
- {% include options/data/selection-access.html %}
-
\ No newline at end of file
diff --git a/docs/_includes/options/data/ajax.html b/docs/_includes/options/data/ajax.html
deleted file mode 100644
index efc65e3e..00000000
--- a/docs/_includes/options/data/ajax.html
+++ /dev/null
@@ -1,213 +0,0 @@
-
-
- Can Select2 be connected to a remote data source?
-
-
-
- Select2 supports connecting to a remote data source using the ajax option.
-
-
-
- How can I set the initially selected options when using AJAX?
-
-
-
- You can refer to the following Stack Overflow answer if you want to set the initial value for AJAX requests: Select2 4.0.0 initial value with AJAX
-
-
-
- What should the results returned to Select2 look like?
-
-
-
- The data returned by the data provider or by processResults should be a JSON object containing an array of objects keyed by the results key.
-
-
- Each object should contain, at a minimum, an id and a text property. The text property will be displayed by default, unless you are using templateResult and templateSelection to customize the way options and selections are rendered.
-
- When options are to be generated in <optgroup> sections, options should be nested under the children attribute of each group object:
-
-{% highlight json linenos %}
-{
- "results": [
- {
- "text": "Group 1",
- "children" : [
- {
- "id": 1,
- "text": "Option 1.1"
- }
- {
- "id": 2,
- "text": "Option 1.2"
- }
- ]
- },
- {
- "text": "Group 2",
- "children" : [
- {
- "id": 3,
- "text": "Option 2.1"
- }
- {
- "id": 4,
- "text": "Option 2.2"
- }
- ]
- }
- ],
- "paginate": {
- "more": true
- }
-}
-{% endhighlight %}
-
-
- Is there a way to modify the response before passing it back to Select2?
-
-
-
- You can use the ajax.processResults option to modify the data returned from the server before passing it to Select2. The data structure returned by processResults should match the format as specified above.
-
- A request is being triggered on every key stroke, can I delay this?
-
-
-
- By default, Select2 will trigger a new AJAX request whenever the user changes their search term. You can set a time limit for debouncing requests using the ajax.delay option.
-
- This will tell Select2 to wait 250 milliseconds before sending the request out to your API.
-
-
-
- How do I tell Select2 which URL to get the results from?
-
-
-
- When connecting Select2 to a remote data source, you have the option of using either a single endpoint (a single page which handles all requests) or a dynamic endpoint (one of many pages). You can point Select2 to a single endpoint during initialization by specifying a string for the ajax.url option.
-
- If there isn't a single url for your search results, or you need to call a function to determine the url to use, you can specify a function for the ajax.url option, and this will be used instead. The query parameters will be passed in through the params option.
-
- I want to add more query parameters to the request, where can this be done?
-
-
-
- By default, Select2 will send the query term as well as the pagination data as query parameters in requests. You can override the data that is sent to your API, or change any of the query parameters, by overriding the ajax.data option.
-
- Select2 expects that the results that are returned from the remote endpoint are already filtered ahead of time based on the search term. If your remote endpoint just returns the list of all possible options, you may be interested in using Select2's support for data arrays.
-
-
-
- Can an AJAX plugin other than jQuery.ajax be used?
-
-
-
- Select2 uses the transport method defined in ajax.transport to send requests to your API. By default, this transport method is jQuery.ajax but this can be changed.
-
- While Select2 is designed to be used with a <select> tag
- the data that is used to search through and display the results can be
- loaded from a JavaScript array using the data option. This
- option should be passed in during the initialization of Select2.
-
- What properties are required on the objects passed in to the array?
-
-
-
- The id and text properties are required on each
- object, and these are the properties that Select2 uses for the internal
- data objects. Any additional paramters passed in with data objects will be
- included on the data objects that Select2 exposes.
-
-
-
- Do the id properties have to be strings?
-
-
-
- Because the value attributes on a <select>
- tag must be strings, the id property on the data objects must
- also be strings. Select2 will attempt to convert anything that is not a
- string to a string, which will work for most situations, but it is
- recommended to force all of your ids to strings ahead of time.
-
-
-
- I can't select results with blank ids or an id of 0!
-
- Nested results should be specified using the children property
- on the data objects that are passed in. This children property
- should be an array of data objects that are grouped under this option, and
- the label for the group should be specified as the text
- property on the root data object.
-
- Because Select2 falls back to an <optgroup> when
- creating nested options, only
- a single level of nesting
- is supported. Any additional levels of nesting is not guaranteed to be
- displayed properly across all browsers and devices.
-
-
-
- Why are <option> tags being created?
-
-
-
- The data option is a shortcut that Select2 provides which
- allows you to load options into your select from a data array.
-
-
- {% include options/not-written.html %}
-
-
- My objects don't use id for their unique identifiers,
- what can I do?
-
-
-
- Select2 requires that the id property is used to uniquely
- identify the options that are displayed in the results list. If you use a
- property other than id (like pk) to uniquely
- identify an option, you need to map your old property to id
- before passing it to Select2.
-
-
-
- If you cannot do this on your server or you are in a situation where the
- identifier cannot be changed, you can do this in JavaScript before passing
- it to Select2.
-
-
-{% highlight js linenos %}
-var data = $.map(yourArrayData, function (obj) {
- obj.id = obj.id || obj.pk; // replace pk with your identifier
-
- return obj;
-});
-{% endhighlight %}
-
-
- My objects use a property other than text for the text that
- needs to be displayed
-
-
-
- Just like with the id property, Select2 requires that the text
- that should be displayed for an option is stored in the text
- property. You can map this property from any existing property using the
- following JavaScript.
-
-
-{% highlight js linenos %}
-var data = $.map(yourArrayData, function (obj) {
- obj.text = obj.text || obj.name; // replace name with the property used for the text
-
- return obj;
-});
-{% endhighlight %}
-
diff --git a/docs/_includes/options/data/select.html b/docs/_includes/options/data/select.html
deleted file mode 100644
index 0e0c98f5..00000000
--- a/docs/_includes/options/data/select.html
+++ /dev/null
@@ -1,69 +0,0 @@
-
-
- Can Select2 be used with a <select> tag?
-
-
-
- Select2 was designed to be a replacement for the standard <select> boxes that are displayed by the browser, so by default it supports all options and operations that are available in a standard select box, but with added flexibility. There is no special configuration required to make Select2 work with a <select> tag.
-
-
-
- Does Select2 support nesting options?
-
-
-
- A standard <select> box can display nested options by wrapping them with in an <optgroup> tag.
-
- Only a single level of nesting is allowed per the HTML specification. If you nest an <optgroup> within another <optgroup>, Select2 will not be able to detect the extra level of nesting and errors may be triggered as a result.
-
-
-
- Can <optgroup> tags be made selectable?
-
-
-
- No. This is a limitation of the HTML specification and is not a limitation that Select2 can overcome. You can emulate grouping by using an <option> instead of an <optgroup> and changing the style by using CSS, but this is not recommended as it is not fully accessible.
-
-
-
- How are <option> and <optgroup> tags serialized into data objects?
-
-
-
- Select2 will convert the <option> tag into a data object based on the following rules.
-
- How to programmatically access a selection data?
-
-
-
- There are few ways to programmatically access the selection data. Calling select2('data') will return the JavaScript array of an objects representing the current selection. Each object will have properties/values which was in the source data objects passed through processResults and templateResult functions (as in Loading data from an array and Connecting to a remote data source).
-
- As Select2 uses the HTML <SELECT> element to store the selection result, the selection data are represented by <OPTION> elements and can be accessed in the plain jQuery/DOM manner:
-
- It is possible to extend the <OPTION> elements representing selection with the HTML data-* attributes containing arbitrary data from the source data objects:
-
-
-{% highlight js linenos %}
-$('select').select2({
- // ...
- templateSelection: function (data, container) {
- $(data.element).attr('data-custom-attribute', data.customValue);
- return data.text;
- }
-});
-
-// Retrieve custom attribute value of the first selected element
-$('select').find(':selected').attr('data-custom-attribute')
-{% endhighlight %}
-
-
- In addition, properties/values from source data objects can ba accessed from within an event handler:
-
-
-{% highlight js linenos %}
-$('select').on('select2:select', function (event) {
- console.log(event.params.data)
-});
-{% endhighlight %}
-
-
\ No newline at end of file
diff --git a/docs/_includes/options/dropdown.html b/docs/_includes/options/dropdown.html
deleted file mode 100644
index 52d8ea25..00000000
--- a/docs/_includes/options/dropdown.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
- Displaying results
-
-
- {% include options/dropdown/filtering.html %}
- {% include options/dropdown/selections.html %}
- {% include options/dropdown/tagging.html %}
- {% include options/dropdown/placement.html %}
-
\ No newline at end of file
diff --git a/docs/_includes/options/dropdown/filtering.html b/docs/_includes/options/dropdown/filtering.html
deleted file mode 100644
index 7e6bce75..00000000
--- a/docs/_includes/options/dropdown/filtering.html
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
- Can I change when search results are loaded?
-
-
-
- Can Select2 wait until the user has typed a search term before triggering the request?
-
-
-{% highlight js linenos %}
-$('select').select2({
- createTag: function (params) {
- // Don't offset to create a tag if there is no @ symbol
- if (params.term.indexOf('@') === -1) {
- // Return null to disable tag creation
- return null;
- }
-
- return {
- id: params.term,
- text: params.term
- }
- }
-});
-{% endhighlight %}
-
- {% include options/not-written.html %}
-
-
- How do I control the placement of the option?
-
-
-{% highlight js linenos %}
-$('select').select2({
- insertTag: function (data, tag) {
- // Insert the tag at the end of the results
- data.push(tag);
- }
-});
-{% endhighlight %}
-
- {% include options/not-written.html %}
-
\ No newline at end of file
diff --git a/docs/_includes/options/events.html b/docs/_includes/options/events.html
deleted file mode 100644
index ea0dd2c1..00000000
--- a/docs/_includes/options/events.html
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
- Events
-
-
- {% include options/events/jquery.html %}
- {% include options/events/internal.html %}
-
\ No newline at end of file
diff --git a/docs/_includes/options/events/internal.html b/docs/_includes/options/events/internal.html
deleted file mode 100644
index 219a4d02..00000000
--- a/docs/_includes/options/events/internal.html
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
- Internal Select2 events
-
-
-
- Select2 has an internal event system that works independently of the DOM event system. This internal event system is only accessible from plugins and adapters that are connected to Select2.
-
- Select2 will trigger a few different events when different actions are taken using the component, allowing you to add custom hooks and perform actions.
-
-
-
-
change
-
Triggered whenever an option is selected or removed.
-
-
select2:close
-
Triggered whenever the dropdown is closed.
-
-
select2:closing
-
Triggered before the dropdown is closed. This event can be prevented.
-
-
select2:open
-
Triggered whenever the dropdown is opened.
-
-
select2:opening
-
Triggered before the dropdown is opened. This event can be prevented.
-
-
select2:select
-
Triggered whenever a result is selected.
-
-
select2:selecting
-
Triggered before a result is selected. This event can be prevented.
-
-
select2:unselect
-
Triggered whenever a selection is removed.
-
-
select2:unselecting
-
Triggered before a selection is removed. This event can be prevented.
-
-
-
- Does Select2 include extra information in these events?
-
-
- {% include options/not-written.html %}
-
-
- How can I attach listeners for these events?
-
-
-{% highlight js linenos %}
-$('select').on('select2:select', function (evt) {
- // Do something
-});
-{% endhighlight %}
-
- {% include options/not-written.html %}
-
-
- What events does Select2 listen for?
-
-
-
- Select2 will listen for the change event on the
- <select> that it is attached to. If you make any
- external changes that need to be reflected in Select2 (such as changing the
- value), you should trigger this event.
-
-
-{% highlight js linenos %}
-$('select').val('US'); // Select the option with a value of 'US'
-$('select').trigger('change'); // Notify any JS components that the value changed
-{% endhighlight %}
-
-
- Can I trigger an event other than change to notify Select2 of changes?
-
-
-
- It's common for other components to be listening to the change
- event, or for custom event handlers to be attached that may have side
- effects. Select2 does not have a custom event (like
- select2:update) that can be triggered other than
- change. You can rely on jQuery's event namespacing to limit
- the scope to Select2 though by triggering the change.select2
- event.
-
-
-{% highlight js linenos %}
-$('select').val('US'); // Change the value or make some change to the internal state
-$('select').trigger('change.select2'); // Notify only Select2 of changes
-{% endhighlight %}
-
-
- What events can be prevented? How can I prevent a selection from being made?
-
-
- {% include options/not-written.html %}
-
\ No newline at end of file
diff --git a/docs/_includes/options/introduction.html b/docs/_includes/options/introduction.html
deleted file mode 100644
index 7cc343fc..00000000
--- a/docs/_includes/options/introduction.html
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
- This page of the documentation is currently undergoing a rewrite and may be incomplete. If you do not find the answer you are looking for on this page, you may have better luck looking at the old options page.
-
-
-
- This documentation is set up in the form of a FAQ and covers the most common questions. If you do not find the answer to your question here, you may want to reach out to the community to see if someone else can answer it.
-
-
\ No newline at end of file
diff --git a/docs/_includes/options/not-written.html b/docs/_includes/options/not-written.html
deleted file mode 100644
index b4967088..00000000
--- a/docs/_includes/options/not-written.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
- This answer to this question has not yet been written. You can improve this documentation by creating a pull request with an answer to this question.
-
\ No newline at end of file
diff --git a/docs/_includes/options/selections.html b/docs/_includes/options/selections.html
deleted file mode 100644
index 086c2aec..00000000
--- a/docs/_includes/options/selections.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
- Displaying selections
-
-
- {% include options/selections/multiple.html %}
- {% include options/selections/placeholder.html %}
- {% include options/selections/clearing-selections.html %}
- {% include options/selections/templating.html %}
-
\ No newline at end of file
diff --git a/docs/_includes/options/selections/clearing-selections.html b/docs/_includes/options/selections/clearing-selections.html
deleted file mode 100644
index 41ca96a8..00000000
--- a/docs/_includes/options/selections/clearing-selections.html
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
- Can I allow users to clear their selections?
-
-
-
- You can allow people to clear their current selections with the allowClear option when initializing Select2. Setting this option to true will enable an "x" icon that will reset the selection to the placeholder.
-
- Can I allow users to make multiple selections?
-
-
-
- Yes, Select2 supports making multiple selections through the use of the multiple option that can be passed in when initializing Select2.
-
-
-
- Can the multiple attribute be used on my <select> element?
-
-
-
- Yes, Select2 will automatically map the value of the multiple attribute to the multiple option during initialization.
-
-
\ No newline at end of file
diff --git a/docs/_includes/options/selections/placeholder.html b/docs/_includes/options/selections/placeholder.html
deleted file mode 100644
index 4d3728da..00000000
--- a/docs/_includes/options/selections/placeholder.html
+++ /dev/null
@@ -1,84 +0,0 @@
-
-
- How can I have Select2 display a placeholder?
-
-
-
- Select2 supports displaying a placeholder by default using the placeholder option. This can be either a data object matching the placeholder option, or a string to display as the placeholder if you are using a blank placeholder option.
-
- My first option is being displayed instead of my placeholder
-
-
-
- This usually means that you do not have a blank <option></option> as the first option in your <select>.
-
-
-
- Note that this does not apply to multiple selects, as the browser does not select the first option by default when multiple selections can be made.
-
-
-
- I am using AJAX, can I still show a placeholder?
-
-
-
- Yes, Select2 supports placeholders for all configurations. You will still need to add in the placeholder option if you are using a single select.
-
-
-
- Can I use an option without a blank value as my placeholder?
-
-
-
- The placeholder option allows you to pass in a data object instead of just a string if you need more flexibility. The id of the data object should match the value of the placeholder option.
-
-
-{% highlight js linenos %}
-$('select').select2({
- placeholder: {
- id: '-1', // the value of the option
- text: 'Select an option'
- }
-});
-{% endhighlight %}
-
-
- Can I change how the placeholder looks?
-
-
-
- When using Select2 when only a single selection can be made, the placeholder option will be passed through the standard templating methods, including the templateSelection option, so you are able to change how it is displayed.
-
- When multiple selections are allowed, the placeholder will be displayed using the placeholder attribute on the search box. You can customize the display of this placeholder using CSS, as explained in the following Stack Overflow answer: Change an input's HTML5 placeholder color with CSS
-
-
-
- My placeholders aren't being displayed in Internet Explorer
-
-
-
- Select2 uses the native placeholder attribute on input boxes for the multiple select, and that attribute is not supported in older versions of Internet Explorer. You need to include Placeholders.js on your page, or use the full build, in order to add placeholder attribute support to input boxes.
-
- How can I customize the way selections are displayed?
-
-
-
- When a selection is made by the user Select2 will display the text of the option by default, just like how it is displayed in a standard select box. You can override the display of the selection by setting the templateSelection option to a JavaScript function.
-
- Nothing is being displayed when I select an option
-
-
- {% include options/not-written.html %}
-
-
- I am using HTML in my selection template but it isn't displaying it
-
-
-
- If you want to use HTML in your selection template, you will need to return a jQuery object. Otherwise, Select2 will assume that your template only returns text and will escape it.
-