Merge branch 'MDL-68196-master' of git://github.com/rezaies/moodle
authorAdrian Greeve <abgreeve@gmail.com>
Thu, 16 Apr 2020 02:55:11 +0000 (10:55 +0800)
committerAdrian Greeve <abgreeve@gmail.com>
Thu, 16 Apr 2020 02:55:11 +0000 (10:55 +0800)
lib/amd/build/form-autocomplete.min.js
lib/amd/build/form-autocomplete.min.js.map
lib/amd/src/form-autocomplete.js

index 7de1001..9c07fdd 100644 (file)
Binary files a/lib/amd/build/form-autocomplete.min.js and b/lib/amd/build/form-autocomplete.min.js differ
index 98bedda..72d5f1b 100644 (file)
Binary files a/lib/amd/build/form-autocomplete.min.js.map and b/lib/amd/build/form-autocomplete.min.js.map differ
index 2cffd17..4738bb6 100644 (file)
@@ -834,6 +834,12 @@ function($, log, str, templates, notification, LoadingIcon) {
         });
         // Whenever the input field changes, update the suggestion list.
         if (options.showSuggestions) {
+            // Store the value of the field as its last value, when the field gains focus.
+            inputElement.on('focus', function(e) {
+                var query = $(e.currentTarget).val();
+                $(e.currentTarget).data('last-value', query);
+            });
+
             // If this field uses ajax, set it up.
             if (options.ajax) {
                 require([options.ajax], function(ajaxHandler) {
@@ -893,7 +899,15 @@ function($, log, str, templates, notification, LoadingIcon) {
                     };
 
                     // Trigger an ajax update after the text field value changes.
-                    inputElement.on("input", throttledHandler);
+                    inputElement.on('input', function(e) {
+                        var query = $(e.currentTarget).val();
+                        var last = $(e.currentTarget).data('last-value');
+                        // IE11 fires many more input events than required - even when the value has not changed.
+                        if (last !== query) {
+                            throttledHandler(e);
+                        }
+                        $(e.currentTarget).data('last-value', query);
+                    });
                 });
             } else {
                 inputElement.on('input', function(e) {