Skip to content
Open
Changes from 2 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
14 changes: 14 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 when the user leaves the input without selecting a suggestion on manually changing the value.
// 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 });
}, 250);
}

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 Down Expand Up @@ -712,6 +725,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