Merge branch 'MDL-65102-master' of git://github.com/rezaies/moodle
authorDavid MonllaĆ³ <davidm@moodle.com>
Mon, 22 Apr 2019 11:16:32 +0000 (13:16 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 23 Apr 2019 11:42:37 +0000 (13:42 +0200)
lib/amd/build/form-autocomplete.min.js
lib/amd/src/form-autocomplete.js

index ccd55f0..0ad553d 100644 (file)
Binary files a/lib/amd/build/form-autocomplete.min.js and b/lib/amd/build/form-autocomplete.min.js differ
index 754f9a6..f46a3c0 100644 (file)
@@ -702,14 +702,27 @@ function($, log, str, templates, notification, LoadingIcon) {
             }
             return true;
         });
+        // Support submitting the form without leaving the autocomplete element,
+        // or submitting too quick before the blur handler action is completed.
+        inputElement.closest('form').on('submit', function() {
+            if (options.tags) {
+                // If tags are enabled, create a tag.
+                addPendingJSPromise('form-autocomplete-submit')
+                .resolve(createItem(options, state, originalSelect));
+            }
+
+            return true;
+        });
         inputElement.on('blur', function() {
             var pendingPromise = addPendingJSPromise('form-autocomplete-blur');
             window.setTimeout(function() {
                 // Get the current element with focus.
                 var focusElement = $(document.activeElement);
 
-                // Only close the menu if the input hasn't regained focus.
-                if (focusElement.attr('id') != inputElement.attr('id')) {
+                // Only close the menu if the input hasn't regained focus, and if the element still exists.
+                // Due to the half a second delay, it is possible that the input element no longer exist
+                // by the time this code is being executed.
+                if (focusElement.attr('id') != inputElement.attr('id') && $('#' + state.inputId).length) {
                     if (options.tags) {
                         pendingPromise.then(function() {
                             return createItem(options, state, originalSelect);