This adds back the `dropdownAutoWidth` option, so the dropdown can
have a width that is automatically determined by the browser. This
works best for smaller dropdowns that contain options with large
amounts of text.
This closes https://github.com/select2/select2/issues/3103.
This closes https://github.com/select2/select2/pull/3113.
Signed-off-by: Kevin Brown <kevin@kevin-brown.com>
The old functionality where classes were directly copied to the
container can be done by setting `dropdownCssClass: ':all:'` when
initializing Select2.
This closes https://github.com/select2/select2/issues/2879.
This improves a regression added in b9b55cec44
that reduced performance for large number of options when using a
jQuery collection object to append multiple options instead of
using a bare array containing the jQuery elements.
As `$.fn.add` is only required for jQuery 1.7.x, we can use a
utility function that only falls back to it for that specific
version of jQuery, and uses `$.fn.append` with an array for all
other versions.
This closes https://github.com/select2/select2/issues/3230.
Since Select2 methods should not be called on an element where
Select2 has not yet been initialized, this raises an error when it
happens. This does not silence the original error, but it does
provide the user with some more context about why they are seeing
a TypeError.
This closes https://github.com/select2/select2/issues/3173.
We now check that the `abort` method actually exists before aborting
the request, as JSONP does not include the `abort` method because
a JSONP request technically cannot be aborted.
This closes https://github.com/select2/select2/issues/3217.
This adds back keyboard support, so you can now clear a selected
item using either the backspace or delete key. This only work when
the container is closed, to prevent issues with the selection being
clear while a user is searching.
This was a regression in accessibility from 3.x.
This closes https://github.com/select2/select2/issues/3224.
Slight performance hit as we are no longer using `qurySelectorAll`,
but it handles the situation a bit more cleanly and prevent future
issues with special characters.
This closes https://github.com/select2/select2/issues/3157.
This fixes the results display so they prefer the `selected`
property on objects over checking if the `id` matches the value of
the underlying select.
We only ignore the `selected` property if it is null, at that point
we compare against the `id` property.
This closes https://github.com/select2/select2/issues/3163.
This also fixes an issue where we were using the `full_name` for
the value instead of the `id` in the example, which technically
wasn't correct.
This closes https://github.com/select2/select2/issues/3148.
Now we can use relative paths in the calls to `require`, so those
using relative builds don't have to worry about modules not being
imported properly. This also makes it considerably easier in the
future when we look to cut down the build sizes and have a custom
builder, as we don't have to worry as much about the paths being
incorrect.
This fixes https://github.com/select2/select2/issues/3014 finally.
Now we do not have separate AMD builds, instead we use a UMD wrapper
to support both AMD and CommonJS environments along with the browser.
This has been tested with RequireJS and it correctly imports Select2
and hooks into jQuery.
This means that all builds will include the Almond AMD loader, but
this isn't that much of an issue when you consider the file sizes.
The loader is namespaced so RequireJS and other AMD builders don't
complain about `require` and `define` existing. This is also done
so AMD loaders don't conflict, as Select2's AMD loader should
operate independently of others.
There are now two layers of wrappers that are applied to files,
only one of which is used for the translation files. This allows
us to only load in the internal Select2 modules once, and in
general makes most things cleaner. These have also been pulled out
into individual JS files instead of being stored in JSON files,
allowing us to add comments and make things look readable.
Because we use a few hacks, these files are heavily commented as well.
This closes https://github.com/select2/select2/issues/2945.
This closes https://github.com/select2/select2/issues/2946.
This finally fixes and adds some integration tests to make sure
that `select2('data')` works as we are expecting. This also adds
tests for `select2('val')` and fixes undefined variable issues
that were spotted because of these tests.
We also no longer date stamp distribution builds.
This closes https://github.com/select2/select2/issues/3104.
This moves the clear icon to the top of the DOM from the bottom to
ensure that it is always visible on top of the selection.
This closes https://github.com/select2/select2/issues/3089.
As jQuery 1.7.2 is the lowest version of jQuery supported by Select2,
it makes sense to run the tests on it. For the most part, we can
assume that the newer versions of Select2 are backwards compatible
enough such that this isn't an issue.
The recommended version of jQuery to use is the latest though, which
is why the jQuery file is only included in the tests.
This revealed a few issues with our data fallbacks and `.append`
functionality that was introduced in jQuery 1.8.
This strips whitespace in tags by default, so multiple tags cannot
be created with only whitespace as the difference in the id.
A test has been added to ensure that this remains fixed in the future.
This closes https://github.com/select2/select2/issues/3076.
This fixes an issue with `select2('data')` that caused it to not
work as intended. Because we were using `Select2.data` for the
data adapter, it was overriding the `Select2.data()` method which
was supposed to be used.
This just renames the `Select2.data` property to
`Select2.dataAdapter` to prevent the naming collision.
This closes https://github.com/select2/select2/issues/3104.
This fixes an issue when using a `<select>` where the elements were
created with XHTML-encoded characters to prevent any injection, as
they would be double-encoded and display incorrectly.
When using a `<select>`, we can assume that the data has already
been encoded because any XSS will have already run before we get to
it. Because of this, we can just use `.text()` instead of `.html()`
to avoid any issues.
This also includes a test to ensure that this does not become an
issue in the future.
This closes https://github.com/select2/select2/issues/3115.
This fixes an issue where the dropdown would not automatically
open when something was typed in the search box on a multiple
select. This was most noticeable when the dropdown closed and
the search box was focused and the user started to type, as the
text would appear in the search box, queries would be sent out to
retrieve results, but the dropdown would not be opened to display
the results.
This also fixes an issue introduced in a recent commit where search
queries would be sent out twice on modern browsers that supported
both the `keyup` and `input` event. The `keyup` event is now
properly debounced for these browsers and the queries are only
going out once.
This closes https://github.com/select2/select2/issues/3036.
Previously, when in results the enter key would select items that
were highlighted if they were not already selected. In the case of
a select where multiple items could be selected, pressing enter
when highlighting a selected item would also allow it to be
unselected. While this seems intuitive for accessibility purposes,
the enter button essentially working as a toggle, it caused some
really strange behavior.
- If the enter button was held down, all previously selected items
would be unselected.
- The enter button did not work the same across both single and
multiple selects.
After listening to user feedback, I have decided to remove the
"enter as toggle" functionality from Select2 and have gone back to
just having the enter button select items. This means that instead
of unselected items that are already selected and highlighted,
Select2 will just close the dropdown. This is the same as what
Select2 would previously do for single selects, so the keyboard
functionality is now the same across both.
Because this removed the only easy way to unselect items in the
dropdown using the keyboard, we had to maintain the toggle
functionality. We decided to implement the toggle functionality
on the CTRL + Space keybinding, which is in line with other
applications. Now when pressing CTRL + Space at the same time in
the dropdown, the highlighted result will behave the same as if the
mouse selected it, which will toggle the current item in multiple
select mode and close the dropdown in single select mode.
This is the same keybinding that Windows Explorer [1] and GTK [2]
use for toggling the current selection, which was why it was picked.
This also fixes an issue where keyboard focus would be lost once an
item was unselected from the results. This was due to a bug in the
CloseOnSelect module that would only automatically close the
dropdown when an item was selected, but not when an item was
unselected. Now the dropdown will be closed automatically when an
item is unselected, which will also cause the selection (and
eventually the search) to be focused.
This fixes two issues described in
https://github.com/select2/select2/issues/3036#issuecomment-76321411.
[1]: http://superuser.com/q/78891/72528
[2]: https://developer.gnome.org/gtk3/stable/GtkIconView.html#GtkIconView-toggle-cursor-item
This fixes an issue where most keys would not trigger the search
in Firefox for Android. There were only a few keys which would
trigger `keyup`, such as space and enter (the search icon), but
they were not consistent. We know that they were being triggered
though, as you could type "new " (note the space) and it would
trigger a search, giving us all states that started with "new".
The problem is that Firefox for Android does not consistently
trigger `keyup` and `keydown` events when a keyboard is used. To
work around the issue, we are now using the `input` event in
replacement of the `keyup` event, which was used to trigger the
search. While this is not an actual `KeyboardEvent` in Chrome, and
lacks some of the important metadata such as `which`/`key` in
Firefox, it works for our implementation.
As the `input` event is not supported in older browsers, such as
those before Internet Explorer 9, we have to listen for both the
old `keyup` event and the new `input` event. As the `input` event
is always triggered before the `keyup` event, we unbind the `keyup`
event automatically to prevent searches from being triggered twice.
This solution was discovered in a blog post by Mathias Bynens at
https://mathiasbynens.be/notes/oninput.
**Note:** The ability to backspace in a blank text field on multiple
selects in order to remove the last selected item does not work in
Firefox for Android because the `keydown` event does not trigger
when the text field is empty. Users can still use the "x" icon
provided at the start of every selected option to achieve the same
effect.
This closes https://github.com/select2/select2/issues/2997.
This also fixes a possible issue where the `< 0` fallback would
not be used because the `minimumResultsForSearch` check would
always return false and never load in the module.
This closes https://github.com/select2/select2/pull/3077.
This fixes the fallback path for the `data-ajax-url` attribute on
elements. As this attribute was previously supported in Select2,
the attribute has been migrated to the new, nested format of the
url and triggers a deprecation warning when it is used. Because
of a fix to the `data-*` attribute parsing made in a9f6d64 that
allowed for nested attributes to be parsed correctly in modern
browsers under jQuery 1.x, the deprecation warning would be
triggered but the attribute would no longer actually be used.
This also fixes some of the `.data` calls to use the camel cased
version of the key instead of the dashed version, which is the
preferred key and will be enforced in future versions of jQuery
as the only way to access data attributes.
Now in situations where the `dataset` attribute is used by Select2,
it combines the results of both `$e.data()` and `e.dataset` when
generating the object containing all of the options. This will
the `dataset` fix to still be used, while also still relying on
jQuery to do additional parsing on any options that it can.
The `dataset` fix is now only used on jQuery 1.x, as that is the
only version of jQuery affected by the dash issue. This is done
using version number parsing on the `$.fn.jquery` property that is
defined by jQuery. As this property is not defined in Zepto and
many other jQuery compatible checks, we only include the fallback
if the property is available. This assumes that any jQuery
compatible libraries that are in use will not include the same dash
issue, which we believe is a safe assumption given that it did not
match the HTML `dataset` specification.
This also adds a few tests to ensure that the deprecated attributes
still continue to function.
This closes https://github.com/select2/select2/issues/3086.
This adds backwards compatibility back into Select2 for `<input />`
tags. The compatibility modules are only available in the full
version and will trigger a warning if a hidden input is being used.
With the new decorator, Select2 should support the basic operations
that it previously did, with the exception of completely overriding
the internal objects. As we no longer expose `data` as a writable
method, it is no longer possible to completely override the selected
data. The state is still managed internally, but in order to prevent
data corruption issues in the past, it is not exposed to the public.
Some small changes needed to be made to how Select2 was dynamically
generating new `<option>` tags, so now a method is called that can
be overridden. In the case of the new decorator, this method is
intercepted and handled without having to actually place the
`<option>` tags into the DOM.
The decorator is applied after all of the other defaults, as the
defaults are not given the current element.
There has only been limited testing with this decorator, primarily
using the `data` and `placeholder` options.
This closes https://github.com/select2/select2/issues/3022.
As we have established already, jQuery 1.x does not correctly handle
`data-*` attributes where there are multiple dashes. This makes it
so we can still handle nested options when working with jQuery 1.x
by using the `.dataset` option that is supported by all major
browsers as well as IE 11+.
Browser support tables for the `.dataset` attributes can be found at
http://caniuse.com/dataset
A notice was already added to the documentation about this in
caeb0ec9b7.
The related ticket in the jQuery repository about this issue is
https://github.com/jquery/jquery/issues/2070.
This closes https://github.com/select2/select2/issues/2969.
Now the focus of the selection container is correctly monitored so
there is a consistent 1px black border on the default theme whenever
it is focused. This requires `focusin`/`focusout` support, which is
supported by all major browsers except for Firefox. In Firefox, the
old focus appearance is still consistent and has not been broken
by this update.
The key handling has also been improved such that some of the logic
detection that was previously done within the search handlers for
multiple select searches is now pushed back to the base selection.
This closes https://github.com/select2/select2/issues/2995.
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.