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.
This adds documentation for the revised `matcher` function, as well
as the compatibility `oldMatcher` function for those who are
upgrading.
This closes https://github.com/select2/select2/issues/2971.
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.
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.
Now that cdnjs is mirroring the beta files, we know what the final
locations are going to be. These identifiers will need to be updated
during the release process, just like all of the others.
This closes https://github.com/select2/select2/issues/2955.
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 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.
In past versions of Select2, the `width` option could be used to
tell Select2 how to determine the width of the container generated
by Select2.
**Breaking change:** The default value for the `width` option has
been changed from `copy` to `resolve.`
**Breaking change:** The old option called `copy` has been renamed
to `style` to better reflect what the width is generated from.
This fixes https://github.com/select2/select2/pull/2090.
This fixes https://github.com/select2/select2/issues/2911.
Tagging should be demonstrated using the multiple select, as that
is where it really shines. It's also how we used to demonstrate it.
This closes https://github.com/select2/select2/issues/2901.
Now Select2 can fire jQuery events that will match the corresponding
internal events. The `open` and `close` events are now publicly
accessible.
The selection adapter was chosen because it is the least likely to
be moved, but handles the most common events. This `EventRelay`
decorator should theoretically be able to decorate any of the
adapters, as they all have the `bind` method that it needs.
The star event will allow us to relay any custom events as well as
the ones used internally by Select2. This also makes it much
easier to start triggering events in general, as we don't need to
relay it in the core anymore.
A module has been created for the jQuery-facing events, and the
release announcement has been updated to mention the event name
changes.
This also adds some documentation about the public events.
There was a plan to universally use an array as the return from
query methods, but now that we've realized pagination and extra
things are impossible without it, we're going back to the return
object. Anyone looking to migrate their data should be returning
an object with the key `results` containing what they previously
returned.
This should fix https://github.com/select2/select2/issues/2898
I'm still not quite sure how this should be handled for the general
case, but for the special case we have this for infinite scrolling,
only on AJAX data.
The documentation for templates still needs to be created.
A warning is now generated in the console for applications using
the previous data attributes that have been migrated.
alt-down/up is the standard way of opening a select when using a
screen reader. This also fixes the gradient in IE, so now it
displays the right colors. Also added a note about Placeholders.js,
so the placeholders on multi-select boxes will work in IE 9 and
below.
Added a disabled state for Select2. This will correctly listen to
property changes (so when the disabled property is changed) and
update the state of Select2 to reflect it.
Added a utility function to find a method to a different context.
With the recent changes to how Select2 works internally, this really
isn't needed. This has been added to make the migration path
easier, and it just internally calls `val` on the underlying select
element. The only difference is that the `val` function will now
convert any non-string elements to strings.
The second argument (`triggerChange`) has not been migrated, as
Select2 now internally relies on the `change` event.
**Note:** As the old `initSelection` method has not been migrated,
it is not possible to set the `val` on remote data sources where
the value has not previously been selected.
`dropdownParent` controls the location of the dropdown when it is
automatically added to the DOM. By default, this is the body
element but it can be modified based on where the user needs it.
This adds a dictionary for converting diacritics to a normalized
representation. This dictionary is used in the default matcher.
The code for stripping the diacritics was pulled from the current
implementation in Select2 3.x.
Now when searching, a loading message is prepended to the top of
the results. This replaces the old spinner image and allows for it
to be translated across different languages.
The loading message can be styled differently and is passed
through the results formatters.
Now the options are mostly generated by hand before being passed
off to jQuery for templating. This fixes much of the speed issues
we had when they were entirely being generated through jQuery.
The matcher example now matches the old matcher example, and the
compatibility module has been turned into a function decorator
instead of a class decorator.
This starts work on the example, which currently uses the GitHub
API.
The `ajax.delay` option has been added that allows for debouncing
requests made within a certain number of milliseconds.
Now that `define` and `require` are never made public, we have to
build everything to support `$.fn.select2.amd` while also working
with other AMD loaders.
Tags no longer takes an array, as pre-existing tags should already
exist as options in the data adapter. A compatibility module will
later be added to convert tag data that is passed in to array data.
Tags allow for users to enter their own options, which will be
added to the beginning of the results list.
This makes quite a few changes, one of the major ones being the
removal of classes for marking options as selected or selectable,
and instead using the ARIA attributes which should already be
present.
Placeholder support has been implemented as a separate module, so
any selection container should be able to be decorated and get
instant placeholder support. It hooks into the updating method of
selections, and determines when to display the placeholder based
on the options that are being updated.
It works in the same way as the old placeholders. If no options
are selected and being displayed, like in the case of a multiple
select, then the placeholder will always be shown. If one option
is being displayed, and the id of the placeholder matches the id
of the selected element, then the placeholder will be shown. This
is similar to the functionality that was present in Select2 2.x,
where the placeholder could be passed in as an object that would
be compared to the selection.
This still requires that, for single selects, the first element
must match the placeholder id. Because the default placeholder id
is a blank string, this will maintain backwards compatibility with
past versions where the first option should be blank. This can
still be overridden to point at a different id, keeping support
for systems where the placeholder doesn't use a blank value.
**Note:** This does not hide the blank option for single selects,
but that will still be maintained for backwards compatibility
within the results module. It will not depend on a placeholder
being present, but instead will hide any options with blank text.