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.
In the past, `initSelection` was used for loading in data objects
for the pre-selected options. Now that Select2 is using a `<select>`
element, there is no need for doing this because the `<option>`
elements should provide the relevant information. So you can now
just pull this information from the remote data source
(or static array, in some cases) and build out the `<option>`
elements manually.
In most cases you don't need to go the full length with a custom
data adapter, but instead are just looking to pre-load elements on
the initial page load.
This improves https://github.com/select2/select2/issues/3116.
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 adds basic documentation explaining that there are compatibility
decorators for `<input type="text" />` support. This is not fully
compatible with all features and requires the use of an external
adapter like the `ArrayAdapter` or `AjaxAdapter` to provide a
reasonable way to query results.
This also triggers a warning if the adapter is used with a hidden
input, as the degraded functionality when there is no JavaScript
support should be discouraged.
The documentation README was previously intended to be read from
the documentation repository, not from the source repository.
This had the potential to give off the impression that documentation
pull requests were not allowed, when exactly the opposite is the
case. The README has been improved to make it more clear how to
contribute pull requests to update the documentation.
Thanks to Brent Connor [1] for pointing out this issue over at
Stack Overflow [2].
[1]: https://stackoverflow.com/users/3954106/brent-connor
[2]: http://stackoverflow.com/q/28705192/359284
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.
This splits out the two templating functions that are referenced in
the documentation. The two functions were previously available in
the source code, but they were not named with the method names that
the documentation referred to.
This closes https://github.com/select2/select2/issues/2993.
It appears as though GitHub has stopped serving the Placeholder.js
GitHub Pages site. This broke placeholder support on older versions
of IE in the documentation and broke the link we had to the
polyfill. Since the repository is still online, and the
documentation should work without an internet connection, the
JavaScript files have been pulled into the documentation folder.
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.