1
0
mirror of synced 2024-11-22 13:06:08 +03:00

Properly disable input handlers in IE

Previously we were only disabling the `input` handler when it was
triggered, which caused a race condition within the `keyup` handlers
which also was triggered by the `input` event. This fixes the issue by
also unbinding the `input` handlers within the `keyup` handler, to avoid
running into the race condition.

Thanks to @Eckankar for pointing out the race condition that still
existed in
66ae2ad1d5

This closes https://github.com/select2/select2/issues/3300
This commit is contained in:
Kevin Brown 2015-11-09 17:33:08 -05:00
parent 6be96cfaa1
commit ca0fd7c195

View File

@ -85,6 +85,14 @@ define([
}
});
// Try to detect the IE version should the `documentMode` property that
// is stored on the document. This is only implemented in IE and is
// slightly cleaner than doing a user agent check.
// This property is not available in Edge, but Edge also doesn't have
// this bug.
var msie = document.documentMode;
var disableInputEvents = msie && msie <= 11;
// Workaround for browsers which do not support the `input` event
// This will prevent double-triggering of events for browsers which support
// both the `keyup` and `input` events.
@ -92,17 +100,10 @@ define([
'input.searchcheck',
'.select2-search--inline',
function (evt) {
// Try to detect the IE version should the `documentMode` property that
// is stored on the document. This is only implemented in IE and is
// slightly cleaner than doing a user agent check.
// This property is not available in Edge, but Edge also doesn't have
// this bug.
var msie = document.documentMode;
// IE will trigger the `input` event when a placeholder is used on a
// search box. To get around this issue, we are forced to ignore all
// `input` events in IE and keep using `keyup`.
if (msie && msie <= 11) {
if (disableInputEvents) {
self.$selection.off('input.search input.searchcheck');
return;
}
@ -116,6 +117,14 @@ define([
'keyup.search input.search',
'.select2-search--inline',
function (evt) {
// IE will trigger the `input` event when a placeholder is used on a
// search box. To get around this issue, we are forced to ignore all
// `input` events in IE and keep using `keyup`.
if (disableInputEvents && evt.type === 'input') {
self.$selection.off('input.search input.searchcheck');
return;
}
var key = evt.which;
// We can freely ignore events from modifier keys