@@ -180,7 +180,22 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
180
180
// Reset the data input, otherwise the value remains and is sent continuously with subsequent requests
181
181
this . dataInput . value = '' ;
182
182
183
- for ( const termIndex of Object . keys ( changedTerms ) ) {
183
+ if ( changedTerms === 'bogus' ) {
184
+ return ;
185
+ }
186
+
187
+ let changedIndices = Object . keys ( changedTerms ) ;
188
+ if ( ! changedIndices . length ) {
189
+ // Perform a partial reset. this.reset() empties the termContainer, which isn't desired here
190
+ this . usedTerms = [ ] ;
191
+ this . lastCompletedTerm = null ;
192
+
193
+ this . registerTerms ( ) ;
194
+ this . togglePlaceholder ( ) ;
195
+ this . termInput . value = '' ;
196
+ }
197
+
198
+ for ( const termIndex of changedIndices ) {
184
199
let label = this . termContainer . querySelector ( `[data-index="${ termIndex } "]` ) ;
185
200
if ( ! label ) {
186
201
continue ;
@@ -563,26 +578,34 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
563
578
return 'noAutoSubmit' in this . input . dataset ;
564
579
}
565
580
566
- autoSubmit ( input , changeType , changedTerms ) {
581
+ autoSubmit ( input , changeType , data ) {
567
582
if ( this . shouldNotAutoSubmit ( ) ) {
568
583
return ;
569
584
}
570
585
571
- if ( changeType === 'save' ) {
586
+ if ( changeType === 'save' && 'terms' in data ) {
572
587
// Replace old term data with the new one, as required by the backend
573
- for ( const termIndex of Object . keys ( changedTerms ) ) {
574
- changedTerms [ termIndex ] = this . usedTerms [ termIndex ] ;
588
+ for ( const termIndex of Object . keys ( data [ 'terms' ] ) ) {
589
+ data [ 'terms' ] [ termIndex ] = this . usedTerms [ termIndex ] ;
575
590
}
576
591
}
577
592
578
- if ( Object . keys ( changedTerms ) . length ) {
579
- this . dataInput . value = JSON . stringify ( {
580
- type : changeType ,
581
- terms : changedTerms
582
- } ) ;
593
+ if ( changeType === 'remove' && ! Object . keys ( data [ 'terms' ] ) . length ) {
594
+ return ;
595
+ }
583
596
584
- $ ( this . input . form ) . trigger ( 'submit' , { submittedBy : input } ) ;
597
+ this . dataInput . value = JSON . stringify ( {
598
+ type : changeType ,
599
+ ...data
600
+ } ) ;
601
+
602
+ let eventData = { submittedBy : input } ;
603
+ if ( changeType === 'paste' ) {
604
+ // Ensure that what's pasted is also transmitted as value
605
+ eventData [ 'terms' ] = this . termsToQueryString ( data [ 'terms' ] ) + this . separator + data [ 'input' ] ;
585
606
}
607
+
608
+ $ ( this . input . form ) . trigger ( 'submit' , eventData ) ;
586
609
}
587
610
588
611
submitTerms ( terms ) {
@@ -691,9 +714,9 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
691
714
this . checkValidity ( input ) ;
692
715
693
716
if ( termIndex >= 0 ) {
694
- this . autoSubmit ( input , 'save' , { [ termIndex ] : this . saveTerm ( input , false , true ) } ) ;
717
+ this . autoSubmit ( input , 'save' , { terms : { [ termIndex ] : this . saveTerm ( input , false , true ) } } ) ;
695
718
} else {
696
- this . autoSubmit ( input , 'exchange' , this . exchangeTerm ( ) ) ;
719
+ this . autoSubmit ( input , 'exchange' , { terms : this . exchangeTerm ( ) } ) ;
697
720
this . togglePlaceholder ( ) ;
698
721
}
699
722
}
@@ -718,7 +741,7 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
718
741
}
719
742
720
743
if ( ! isTerm ) {
721
- this . autoSubmit ( this . input , 'remove' , this . clearSelectedTerms ( ) ) ;
744
+ this . autoSubmit ( this . input , 'remove' , { terms : this . clearSelectedTerms ( ) } ) ;
722
745
this . togglePlaceholder ( ) ;
723
746
}
724
747
}
@@ -774,7 +797,7 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
774
797
}
775
798
776
799
this . togglePlaceholder ( ) ;
777
- this . autoSubmit ( input , 'remove' , removedTerms ) ;
800
+ this . autoSubmit ( input , 'remove' , { terms : removedTerms } ) ;
778
801
break ;
779
802
case 'Delete' :
780
803
removedTerms = this . clearSelectedTerms ( ) ;
@@ -795,7 +818,7 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
795
818
}
796
819
797
820
this . togglePlaceholder ( ) ;
798
- this . autoSubmit ( input , 'remove' , removedTerms ) ;
821
+ this . autoSubmit ( input , 'remove' , { terms : removedTerms } ) ;
799
822
break ;
800
823
case 'Enter' :
801
824
if ( termIndex >= 0 ) {
@@ -847,7 +870,7 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
847
870
848
871
break ;
849
872
case 'Delete' :
850
- this . autoSubmit ( event . target , 'remove' , this . clearSelectedTerms ( ) ) ;
873
+ this . autoSubmit ( event . target , 'remove' , { terms : this . clearSelectedTerms ( ) } ) ;
851
874
this . togglePlaceholder ( ) ;
852
875
break ;
853
876
}
@@ -873,10 +896,11 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
873
896
if ( this . readPartialTerm ( input ) ) {
874
897
let previousTerm = this . saveTerm ( input ) ;
875
898
if ( previousTerm !== false ) {
876
- this . autoSubmit ( input , 'save' , { [ termIndex ] : previousTerm } ) ;
899
+ this . autoSubmit ( input , 'save' , { terms : { [ termIndex ] : previousTerm } } ) ;
877
900
}
878
901
} else {
879
- this . autoSubmit ( input , 'remove' , { [ termIndex ] : this . removeTerm ( input . parentNode ) } ) ;
902
+ this . autoSubmit (
903
+ input , 'remove' , { terms : { [ termIndex ] : this . removeTerm ( input . parentNode ) } } ) ;
880
904
}
881
905
}
882
906
} , 0 ) ;
@@ -923,11 +947,14 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
923
947
}
924
948
925
949
onPaste ( event ) {
926
- if ( this . shouldNotAutoSubmit ( ) || this . hasTerms ( ) || this . input . value ) {
950
+ if ( this . shouldNotAutoSubmit ( ) || this . input . value ) {
927
951
return ;
928
952
}
929
953
930
- this . autoSubmit ( this . input , 'paste' , [ event . clipboardData . getData ( 'text/plain' ) ] ) ;
954
+ this . autoSubmit ( this . input , 'paste' , {
955
+ input : event . clipboardData . getData ( 'text/plain' ) ,
956
+ terms : this . usedTerms
957
+ } ) ;
931
958
932
959
event . preventDefault ( ) ;
933
960
}
@@ -953,7 +980,7 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
953
980
954
981
if ( event . type === 'cut' ) {
955
982
this . clearPartialTerm ( this . input ) ;
956
- this . autoSubmit ( this . input , 'remove' , this . clearSelectedTerms ( ) ) ;
983
+ this . autoSubmit ( this . input , 'remove' , { terms : this . clearSelectedTerms ( ) } ) ;
957
984
this . togglePlaceholder ( ) ;
958
985
}
959
986
}
0 commit comments