Skip to content
Open
Changes from 1 commit
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
15 changes: 13 additions & 2 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.hasNotBeenCompleted = false; // Flag to identify if the input has been completed at least once.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below: ! this.hasNotBeenCompleted

Double negation.

Suggestion: this.hasBeenManuallyChanged

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.hasNotBeenCompleted = false;

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

onFocusOut(event) {
if (this.completedInput === null) {
if (this.completedInput === null && (this.instrumented || ! this.hasNotBeenCompleted)) {
// 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
// that's the one which has a completed input set.
Expand All @@ -492,12 +494,20 @@ define(["../notjQuery"], function ($) {
&& ! this.termSuggestions.contains(document.activeElement)
) {
// Hide the suggestions if the user doesn't navigate them
if (input !== completedInput) {
if (completedInput !== null && input !== completedInput) {
// Restore input if a suggestion lost focus
this.suggest(completedInput, this.completedValue);
}

this.hideSuggestions();

// Autosubmit when the user leaves without selecting a suggestion on manual input.
// Only for non-instrumented mode — instrumented inputs (e.g. TermInput) handle
// autosubmit themselves via BaseInput.autoSubmit() with proper term data.
if (! this.instrumented && this.shouldAutoSubmit()) {
this.hasNotBeenCompleted = false;
$(input.form).trigger('submit', { submittedBy: input });
}
}
}, 250);
}
Expand Down Expand Up @@ -712,6 +722,7 @@ define(["../notjQuery"], function ($) {

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

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