MDL-65102 core_form: autocomplete element to handle submit event

This commit is contained in:
Shamim Rezaie
2019-03-27 19:00:27 +11:00
parent 3271c39c74
commit 072a033a79
2 changed files with 16 additions and 3 deletions
File diff suppressed because one or more lines are too long
+15 -2
View 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);