1
0
mirror of synced 2024-11-26 23:06:02 +03:00

Fix input event in IE

This closes https://github.com/select2/select2/issues/3300
This closes https://github.com/select2/select2/pull/3677
This commit is contained in:
Kevin Brown 2015-08-21 14:46:50 -04:00
parent ab14751507
commit 66ae2ad1d5

View File

@ -88,27 +88,49 @@ define([
// Workaround for browsers which do not support the `input` event // Workaround for browsers which do not support the `input` event
// This will prevent double-triggering of events for browsers which support // This will prevent double-triggering of events for browsers which support
// both the `keyup` and `input` events. // both the `keyup` and `input` events.
this.$selection.on('input', '.select2-search--inline', function (evt) { this.$selection.on(
// Unbind the duplicated `keyup` event 'input.searchcheck',
self.$selection.off('keyup.search'); '.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;
this.$selection.on('keyup.search input', '.select2-search--inline', // IE will trigger the `input` event when a placeholder is used on a
function (evt) { // search box. To get around this issue, we are forced to ignore all
var key = evt.which; // `input` events in IE and keep using `keyup`.
if (msie && msie <= 11) {
self.$selection.off('input.search input.searchcheck');
return;
}
// We can freely ignore events from modifier keys // Unbind the duplicated `keyup` event
if (key == KEYS.SHIFT || key == KEYS.CTRL || key == KEYS.ALT) { self.$selection.off('keyup.search');
return;
} }
);
// Tabbing will be handled during the `keydown` phase this.$selection.on(
if (key == KEYS.TAB) { 'keyup.search input.search',
return; '.select2-search--inline',
function (evt) {
var key = evt.which;
// We can freely ignore events from modifier keys
if (key == KEYS.SHIFT || key == KEYS.CTRL || key == KEYS.ALT) {
return;
}
// Tabbing will be handled during the `keydown` phase
if (key == KEYS.TAB) {
return;
}
self.handleSearch(evt);
} }
);
self.handleSearch(evt);
});
}; };
/** /**