Previously Select2 would assume that the tab index for the
`<select>` was `0`, which is the browser default. Now Select2 will
clone the tab index from the original element, and correctly restore
it when it is destroyed or disabled/enabled.
This closes https://github.com/select2/select2/issues/3031.
There were a few undefined variables being referenced within the
Select2 code. The JSHint configuration has been modified to fail
if there are undefined variables being referenced, including any
global variables.
There is an exception that is being made for the jQuery shim, as it
must try to find the global jQuery references.
An exception is made for the test helpers, as the SauceLabs reporting
variables are not camelCase, and would normally trigger warnings.
This closes https://github.com/select2/select2/pull/3028.
This copies the `title` attribute of `<option>` and `<optgroup>`
tags to the `title` attribute of the options within the results
list and the selection when it is rendered.
For single selections, the `text` property on the data objects will
be used if the `title` attribute is not present, which will allow
for long names to still be viewable if they overflow the selection
container.
This also fixes a potential issue in browsers that did not support
the non-standard `innerText` property on DOM nodes. As the
`textContent` property is the standard, and it is supported on
IE 9+, we try to set that before falling back to `innerText`.
This closes https://github.com/select2/select2/issues/2530.
This closes https://github.com/select2/select2/pull/2889.
In the past, `select2("data")` allowed you to retrieve the currently
selected data objects. Read-only support has been added back for
this, which maps to the `current` method of the data adapter. This
will only work for data adapters which allow for the synchronous
retrieval of the current data, which is the case for all of the
default data adapters.
You could also previously overwrite the currently selected data
objects by passing in an argument to `select2("data")`. As this
dealt directly with the internals, and required a considerable
amount of work to synchronize it, it has been removed. A warning
will now be triggered if the method is called with additional
elements, and the `val` method should be used instead.
This closes https://github.com/select2/select2/issues/2938.
This adds `StopPropagation` modules that will stop the propagation
of the most common events from the selection and dropdown containers.
These modules work from a list of 21 common events, most of which
were stopped by default in past versions, and call `stopPropagation`
on them when they are detected at the container level.
These modules are only available in full builds of Select2.
This closes https://github.com/select2/select2/issues/2033.
This closes https://github.com/select2/select2/issues/2974.
This adds documentation for the `templateResult` and
`templateSelection` options. The fact that placeholders and
custom messages are templated was noted, although most people
should be using the standard `text` property that they provide
anyway. This fixes the templating link provided in the release
announcement to link to the correct location in the documentation.
This also adds support for the `templateSelection` function to
return a DocumentFragment or jQuery compatible object to be
passed back and rendered.
This closes https://github.com/select2/select2/issues/3005.
This closes https://github.com/select2/select2/issues/3019.
The `closeOnSelect` option was previously used to control whether
or not the dropdown was closed when an option was selected. This
could be simulated by triggering the `open` event after the `close`
event was received, but it makes sense to abstract it out into a
decorator.
This also adds support for not closing the dropdown when the control
key is being held. This is useful when multiple options need to be
selected in quick succession, so the dropdown does not have to be
reopened.
This also adds documentation that covers both changes.
This closes https://github.com/select2/select2/pull/2735.
This closes https://github.com/select2/select2/issues/3017.
This also fixes the case where `templateResult` does not return a
string, where it will fall back to jQuery to set the value of the
option. This allows for the `templateResult` function to return a
jQuery or DOM element that contains the templated data.
Just like with the translation methods, only strings returned from
`templateResult` will be escaped.
The old flag icons have been transferred from the old repository to
the documentation, for use in the templates. Unfortunately I cannot
find a license for them, but I suspect a license isn't actually
needed considering the state flags are public.
This closes https://github.com/select2/select2/issues/3005.
This closes https://github.com/select2/select2/issues/818.
Select2 previously had an issue displaying the text of long values
as it was not correctly wrapping the text. This was because the
browser did not know that it couldn't wrap at whitespace, which
has been fixed.
Now Select2 should properly display an ellipsis for large text
values instead of overflowing.
This closes https://github.com/select2/select2/issues/2984.
In a single select, the search field is automatically focused when
the select is opened. This also applied to multiple selects, but
this was causing issues because the container was automatically
focused when the dropdown was closed.
This makes a change such that the search field is automatically
focused when the dropdown is closed.
This closes https://github.com/select2/select2/issues/2995.
The search box previously displayed a clear icon on the far right
side in webkit-based browsers, specifically Chrome and Safari. This
hides the clear icon in those browsers, and also fixes a slight
sizing issue, so it should no longer be displayed.
This also disables autocorrect, autocompleted, as well as a few
other automatic search corrections on the field, so mobile devices
should have a better experience.
This closes https://github.com/select2/select2/issues/3018.
In past versions of Select2, supplying a value less than zero to
`minimumResultsForSearch` acted the same as providing a high value,
such as `Infinity`. This corrects the regression by mapping anything
less than zero to the value `Infinity`.
This closes https://github.com/select2/select2/issues/2994.
It is assumed that DOM elements or related objects will have been
escaped before they are passed back from templating functions. As
strings are typically blinding concatenated, like in our defaults,
it makes sense to escape the markup within them.
This is related to https://github.com/select2/select2/issues/3005.
Translations will now be passed through `escapeMarkup` and injected
into the results messages as HTML just like the templating options
for the the results and selections. This fixes the regression from
3.x where the old formatters always supported HTML.
This closes https://github.com/select2/select2/issues/3008.
The `allowClear` option may not work as intended if a placeholder
is not used. This is becaise the placeholder holds the value that
the `<select>` should be reset to when the `x` is hit.
An error is now properly raised in the console when Select2 detects
that the `allowClear` option is used without the `placeholder`
option.
This closes https://github.com/select2/select2/issues/3016.
This adds back the `ajax.transport` option, which allows anyone to
use their own AJAX backend. By default, `jQuery.ajax` is used as the
default transport backend.
**Breaking change:** Instead of taking `params` that contains a
`success` and `error` keys for the callback, two new callback
parameters are passed alongside of `params` that should be called
when the request succeeds or fails.
This closes https://github.com/select2/select2/issues/2987.
This is needed to escape any bad markup that is passed through
user-entered data. Users can prevent their markup from being
escaped by using a no-op `escapeMarkup` function.
This closes https://github.com/select2/select2/issues/2990.
Now we are using `jQuery.noConflict()` in tests, so it should be
slightly easier to detect when this happens next time. Tests just
need to be written for the component.
This closes https://github.com/select2/select2/issues/2985.
This prevents scrolling within scrollable containers (excluding the
dropdown) when the dropdown is open. This fixes an issue where the
dropdown would go out of sync with the parent container when the
parent container was scrolled.
We did not have this issue in past versions of Select2 because the
mask prevented any scrolling. Now that we have removed the mask, we
have to deal with scrolling from different areas of the page.
We initially tried to hook into the `scroll` events of the parent
containers, but because of a list of issues we decided against it.
If the container scrolled out of view, the dropdown would still be
left open and above everything else, even though the container
wasn't visually connected to it.
The `scroll` event does not bubble, so we need to attach the `scroll`
handler to every parent element that is scrollable. Since it is
surprisingly difficult to determine if an element is scrollable,
we modified some CC-BY-SA code and use that to determine if the
element has a scrollbar. The original `hasScroll` function can be
found at http://codereview.stackexchange.com/q/13338, the same link
left within the code, and was originally designed to be a sizzle
selector. As Select2 does not require a sizzle-compatible version of
jQuery, we converted it into a function that could be used with
`.filter` to filter down the elements.
This closes https://github.com/select2/select2/issues/2975.
Select2 did not previously have a high enough `z-index` for it to
be displayed over modals. The `z-index` has been raised to 1051,
so now it should appear over the jQuery UI and Bootstrap modals.
This closes https://github.com/select2/select2/issues/2958.
When Select2 is not used with a design that universally sets
`box-sizing: border-box` to elements, the search box previously
would take up more space than expected. This fixed the issue by
adding the `box-sizing` rule to the search box.
This closes https://github.com/select2/select2/issues/2978.
When we re-implemented support for responsive widths, through the
use of percentages, we never moved the support over to the dropdowns.
So the dropdowns generally were not large enough, and when resized
they never re-adjusted, and they didn't fully work as intended.
This fixes the issue by automatically resizing the dropdown whenever
it is repositioned, mainly to handle new scrollbars, which will
ensure that it is always the same width as the container.
This also adds a section to the examples for responsive design,
just like in the old documentation.
This closes https://github.com/select2/select2/issues/2949.
This reverts the changes (from 3.5.x) to the scroll detection, so
Select2 will still reposition itself every time the window is
scrolled or resized. This has the benefit of fixing the issue when
the screen jumps if the dropdown is too high, which would previously
close the dropdown.
Select2 will also correctly set the positioning if it is pushed out
of the top of the viewport. Due to an unexpected bug, Select2 would
previously still display above the container, but would be styled
as if it were below it.
This closes https://github.com/select2/select2/issues/2961.
This closes https://github.com/select2/select2/issues/2956.
This fixes an issue where an `unselect` event would be incorrectly
triggered when the selected option was selected again in a single
select. This has been fixed now, so the even will only be triggered
for multiple selects. The `close` event will still be triggered
though, so the functionality will still remain the same to the user.
This closes https://github.com/select2/select2/issues/2959.
The `selectOnClose` option did not work in production because we
were decorating the `dropdownAdapter` instead of the `resultsAdpater`
when automatically generating the adapters. This has now been fixed,
and the option should work without errors in production.
This also adds documentation for the `selectOnClose` option.
This closes https://github.com/select2/select2/issues/2953.
This adds a check that triggers an error if Select2 was not able
to detect a copy of jQuery on the page. This should help users when
they are setting up Select2.
**Breaking change:** The full build no longer includes jQuery.
Previously, the full build included all requirements for Select2,
including jQuery, which meant that anyone looking for the optional
requirements had to possibly include multiple versions of jQuery
on their page. This means that anyone requiring Select2 to also
bundle jQuery will now need to include jQuery on their pages
alongside Select2. A copy of jQuery is included in the repository.
**Breaking change:** The AMD build of Select2 will now correctly
wrap the code in a `define` block. It will still create the named
blocks inside of the code, which should be valid in most AMD build
systems, so now Select2 is compatible with cases where the file
does not have the same name as the Select2 module name.
**Breaking change:** Select2 will re-use the AMD methods if they
are available on the page, but it will not longer leak the included
AMD loader to the global scope. The AMD methods will still be
available on the `jQuery.fn.select2.amd` namespace.
The `mock.js` test file has been renamed to `helpers.js` and will
handle the escalation of the `require` and `define` variables to
the global scope. It should be included in all test files, or the
tests will fail.
This closes https://github.com/select2/select2/issues/2946.
When `jQuery.noConflict` is called, the global `$` variable is not
defined. We cannot assume in the code that the variable is defined,
and instead should always make sure to import the `jquery` module
when we need jQuery.
This fixes all of the issues where we are assuming that `$` is
defined globally when we are not importing the module. This also
fixes the issues when defining the `jQuery.fn.select2.amd` modules
where we were always attaching to the `$` object instead of the
`jQuery` object.
This closes https://github.com/select2/select2/issues/2947.
In the past, Select2 triggered the `select2-clearing` event when
clearing the placeholder. This has been switched to the `unselect`
event which is now triggered whenever the placeholder is cleared.
The placeholder can also be prevented if the `unselecting` event
is prevented.
This will also trigger the event when deleting every option from
the multiple select, so it is possible for the `unselecting` event
to be triggered multiple times when clearing a multiple select.
This adds tests to ensure that the `allowClear` option always works.
This closes https://github.com/select2/select2/issues/2954.
This should prevent users from running into unexpected errors when
they do not return an object with the `results` key containing an
array.
This closes https://github.com/select2/select2/issues/2950.
If the language that is passed in through the options is just a
string, like "en-US" or "pt-BR", Select2 will now try to load the
base language along with the requested language and "en". So
requesting "pt-BR" will try to load "pt-BR", "pt", and "en".
This also catches errors and triggers a warning about not being
able to load the file. This should be a more user friendly error,
and it fixes the problem where Select2 would completely fail to
initialize if a language could not be found.
This closes https://github.com/select2/select2/issues/2934.
Previously this would return `style` if it couldn't be resolved and
the `style` attribute on the element is set for some reason. Now it
will return `null`, because it tried to resolve the width but was
not able to. This will allow it to fall back to `element` by default,
or not set the width at all.
This closes https://github.com/select2/select2/issues/2935.
This exposes the default options for Select2 as
`$.fn.select2.defaults`. A default option can be set using the
`set(key, val)` option which is available. The key should use the
same formatting as the HTML data attributes.
This also adds some documentation about it.
This also adds more documentation and corrects the release notes
for these breaking changes. These modules will now only be included
in the full builds of Select2, which has been noted in a few places.
This adds basic tests to ensure that the selection is accessible by
all users. This checks for common attributes, ensuring that the
container is always keyboard accessible and follows ARIA guidelines.
This also changes the base selection to create a common element so
we don't need to repeat attributes and such across multiple selection
containers.
This adds backwards compatibility with the `query` option so it
automatically patches the `DataAdapter.query` function. The only
major difference between the methods is the call signature, which
has now moved the callback out of the parameters and into the second
argument.
This also adds tests that verify that the old query functions should
work as expected.
Now if the old `initSelection` method is used, a warning will be
triggered in the console informing the user that it has now been
changed to `DataAdapter.current`, and they should create a custom
data adapter instead. We will still only call `initSelection` once,
and then default back to the old data adapter for calls after that.
This allows for mostly transparent support between versions.
This adds tests to ensure that `initSelection` operates the same as
it previously did, but now patches the `current` method of the
default data adapter.
This adds detailed docs explaining how you can convert the old
implementations of `query` and `initSelection` into a custom data
adapter using the `current` and `query` methods provided there.
Examples are included that should make it considerably easier to
handle.
This adds the `select` and `unselect` events so users can still
hook into them from their jQuery plugins.
This also modifies the core `trigger` to fire pre-events that can
be canceled for the `open`, `close`, `select`, and `unselect`
events. Users implementing these events who need to handle cases
where the event has been prevented should check `args.prevented`,
where `args` is the object that was included for arguments when
triggering the internal event.