@@ -6,7 +6,7 @@ define(["../notjQuery"], function ($) {
66 constructor ( input , instrumented = false ) {
77 this . input = input ;
88 this . instrumented = instrumented ;
9- this . hasNotBeenCompleted = false ; // Flag to identify if the input has been completed at least once .
9+ this . hasBeenManuallyChanged = false ; // Flag to identify if the input has been manually changed .
1010 this . selectionStartInput = null ;
1111 this . selectionActive = false ;
1212 this . mouseSelectionActive = false ;
@@ -269,7 +269,7 @@ define(["../notjQuery"], function ($) {
269269
270270 complete ( input , value , data ) {
271271 $ ( input ) . focus ( { scripted : true } ) ;
272- this . hasNotBeenCompleted = false ;
272+ this . hasBeenManuallyChanged = false ;
273273
274274 if ( this . instrumented ) {
275275 if ( ! Object . keys ( data ) . length ) {
@@ -478,7 +478,18 @@ define(["../notjQuery"], function ($) {
478478 }
479479
480480 onFocusOut ( event ) {
481- if ( this . completedInput === null && ( this . instrumented || ! this . hasNotBeenCompleted ) ) {
481+ // Autosubmit when the user leaves the input without selecting a suggestion on manually changing the value.
482+ // Only for non-instrumented mode — instrumented inputs (e.g. TermInput) handle
483+ // autosubmit themselves via BaseInput.autoSubmit() with proper term data.
484+ if ( ! this . instrumented && this . hasBeenManuallyChanged && this . shouldAutoSubmit ( ) ) {
485+ this . hasBeenManuallyChanged = false ;
486+ let input = event . target ;
487+ setTimeout ( ( ) => {
488+ $ ( input . form ) . trigger ( 'submit' , { submittedBy : input } ) ;
489+ } , 250 ) ;
490+ }
491+
492+ if ( this . completedInput === null ) {
482493 // If there are multiple instances of Completer bound to the same suggestion container
483494 // all of them try to handle the event. Though, only one of them is responsible and
484495 // that's the one which has a completed input set.
@@ -494,20 +505,12 @@ define(["../notjQuery"], function ($) {
494505 && ! this . termSuggestions . contains ( document . activeElement )
495506 ) {
496507 // Hide the suggestions if the user doesn't navigate them
497- if ( completedInput !== null && input !== completedInput ) {
508+ if ( input !== completedInput ) {
498509 // Restore input if a suggestion lost focus
499510 this . suggest ( completedInput , this . completedValue ) ;
500511 }
501512
502513 this . hideSuggestions ( ) ;
503-
504- // Autosubmit when the user leaves without selecting a suggestion on manual input.
505- // Only for non-instrumented mode — instrumented inputs (e.g. TermInput) handle
506- // autosubmit themselves via BaseInput.autoSubmit() with proper term data.
507- if ( ! this . instrumented && this . shouldAutoSubmit ( ) ) {
508- this . hasNotBeenCompleted = false ;
509- $ ( input . form ) . trigger ( 'submit' , { submittedBy : input } ) ;
510- }
511514 }
512515 } , 250 ) ;
513516 }
@@ -722,7 +725,7 @@ define(["../notjQuery"], function ($) {
722725
723726 onInput ( event ) {
724727 let input = event . target ;
725- this . hasNotBeenCompleted = true ;
728+ this . hasBeenManuallyChanged = true ;
726729
727730 if ( input . minLength > 0 && input . value . length < input . minLength ) {
728731 return ;
0 commit comments