MDL-51964 autocomplete: IE11 fires spurious "input" events
authorDamyon Wiese <damyon@moodle.com>
Fri, 30 Oct 2015 04:15:28 +0000 (12:15 +0800)
committerDamyon Wiese <damyon@moodle.com>
Mon, 2 Nov 2015 02:11:13 +0000 (10:11 +0800)
We need to check for "real" changes to the input value because
ie11 is just firing events willy nilly.

lib/amd/build/form-autocomplete.min.js
lib/amd/src/form-autocomplete.js

index 1435ea1..c3b3a5f 100644 (file)
Binary files a/lib/amd/build/form-autocomplete.min.js and b/lib/amd/build/form-autocomplete.min.js differ
index 7308ce1..05cdc6c 100644 (file)
@@ -693,7 +693,17 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
         // Whenever the input field changes, update the suggestion list.
         inputElement.on('input', function(e) {
             var query = $(e.currentTarget).val();
-            updateSuggestions(query, inputId, suggestionsId, originalSelect, multiple, tags, caseSensitive);
+            var last = $(e.currentTarget).data('last-value');
+            if (typeof last === 'undefined') {
+                last = query;
+            }
+            // IE11 fires many more input events than required - even when the value has not changed.
+            // We need to only do this for real value changed events or the suggestions will be
+            // unclickable on IE11 (because they will be rebuilt before the click event fires).
+            if (last != query) {
+                updateSuggestions(query, inputId, suggestionsId, originalSelect, multiple, tags, caseSensitive);
+                $(e.currentTarget).data('last-value', query);
+            }
         });
     };