Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 3.6
-
Component/s: Forms Library
-
Labels:
-
Sprint:Workplace for Moodle 3.7
Description
I am working on a modal form that contains an autocomplete element to add tags and I just found out that if I type a new tag and I press Save on the form (without pressing enter or clicking anywhere else in the form) I get this exception message:
jquery-3.2.1.js:3860 jQuery.Deferred exception: Cannot read property 'split' of undefined TypeError: Cannot read property 'split' of undefined at createItem |
This happens because on blur tries to work with an element that no longer exists. One proposal to solve this problem that Marina gave me could be adding
&& $('#' + state.inputId).length |
on this if condition:
--- a/lib/amd/src/form-autocomplete.js
|
+++ b/lib/amd/src/form-autocomplete.js
|
@@ -709,7 +709,7 @@ function($, log, str, templates, notification, LoadingIcon) { |
var focusElement = $(document.activeElement); // Only close the menu if the input hasn't regained focus. |
- if (focusElement.attr('id') != inputElement.attr('id')) { |
+ if (focusElement.attr('id') != inputElement.attr('id') && $('#' + state.inputId).length) { |
if (options.tags) { |
pendingPromise.then(function() {
|
return createItem(options, state, originalSelect); |