Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions asset/js/widget/Completer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define(["../notjQuery"], function ($) {
constructor(input, instrumented = false) {
this.input = input;
this.instrumented = instrumented;
this.hasBeenManuallyChanged = false; // Flag to identify if the input has been manually changed.
this.selectionStartInput = null;
this.selectionActive = false;
this.mouseSelectionActive = false;
Expand Down Expand Up @@ -268,6 +269,7 @@ define(["../notjQuery"], function ($) {

complete(input, value, data) {
$(input).focus({ scripted: true });
this.hasBeenManuallyChanged = false;

if (this.instrumented) {
if (! Object.keys(data).length) {
Expand Down Expand Up @@ -476,6 +478,17 @@ define(["../notjQuery"], function ($) {
}

onFocusOut(event) {
// Autosubmit if the user leaves the input and the input has been manually changed.
// Only for non-instrumented mode — instrumented inputs (e.g. TermInput) handle
// autosubmit themselves via BaseInput.autoSubmit() with proper term data.
if (! this.instrumented && this.hasBeenManuallyChanged && this.shouldAutoSubmit()) {
this.hasBeenManuallyChanged = false;
let input = event.target;
setTimeout(() => {
$(input.form).trigger('submit', { submittedBy: input });
}, 300);
}

if (this.completedInput === null) {
// If there are multiple instances of Completer bound to the same suggestion container
// all of them try to handle the event. Though, only one of them is responsible and
Expand All @@ -498,6 +511,7 @@ define(["../notjQuery"], function ($) {
}

this.hideSuggestions();
this.hasBeenManuallyChanged = true;
}
}, 250);
}
Expand Down Expand Up @@ -655,6 +669,7 @@ define(["../notjQuery"], function ($) {
break;
case 'Tab':
suggestions = this.termSuggestions.querySelectorAll('[type="button"]');
this.hasBeenManuallyChanged = false;
if (suggestions.length === 1) {
event.preventDefault();
let input = event.target;
Expand All @@ -676,13 +691,15 @@ define(["../notjQuery"], function ($) {
break;
case 'Escape':
if (this.hasSuggestions()) {
this.hasBeenManuallyChanged = true;
this.hideSuggestions()
event.preventDefault();
}

break;
case 'ArrowUp':
suggestions = this.termSuggestions.querySelectorAll('[type="button"]');
this.hasBeenManuallyChanged = false;
if (suggestions.length) {
event.preventDefault();
this.moveToSuggestion(true);
Expand All @@ -691,6 +708,7 @@ define(["../notjQuery"], function ($) {
break;
case 'ArrowDown':
suggestions = this.termSuggestions.querySelectorAll('[type="button"]');
this.hasBeenManuallyChanged = false;
if (suggestions.length) {
event.preventDefault();
this.moveToSuggestion();
Expand All @@ -712,6 +730,7 @@ define(["../notjQuery"], function ($) {

onInput(event) {
let input = event.target;
this.hasBeenManuallyChanged = true;

if (input.minLength > 0 && input.value.length < input.minLength) {
return;
Expand Down
Loading