Skip to content

Commit a44cf9f

Browse files
committed
Merge pull request select2#2003 from jdecuyper/feature-next-search-term-multiple
Enable nextSearchTerm function for multiple select
2 parents 29b88e3 + c7dd8c5 commit a44cf9f

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

select2.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,6 +2722,15 @@ the specific language governing permissions and limitations under the Apache Lic
27222722

27232723
this.focusSearch();
27242724

2725+
// initializes search's value with nextSearchTerm (if defined by user)
2726+
// ignore nextSearchTerm if the dropdown is opened by the user pressing a letter
2727+
if(this.search.val() === "") {
2728+
if(this.nextSearchTerm != undefined){
2729+
this.search.val(this.nextSearchTerm);
2730+
this.search.select();
2731+
}
2732+
}
2733+
27252734
this.updateResults(true);
27262735
this.search.focus();
27272736
this.opts.element.trigger($.Event("select2-open"));
@@ -2786,6 +2795,9 @@ the specific language governing permissions and limitations under the Apache Lic
27862795

27872796
this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
27882797

2798+
// keep track of the search's value before it gets cleared
2799+
this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val());
2800+
27892801
this.clearSearch();
27902802
this.updateResults();
27912803

@@ -2802,6 +2814,13 @@ the specific language governing permissions and limitations under the Apache Lic
28022814
// if we reached max selection size repaint the results so choices
28032815
// are replaced with the max selection reached message
28042816
this.updateResults(true);
2817+
} else {
2818+
// initializes search's value with nextSearchTerm and update search result
2819+
if(this.nextSearchTerm != undefined){
2820+
this.search.val(this.nextSearchTerm);
2821+
this.updateResults();
2822+
this.search.select();
2823+
}
28052824
}
28062825
this.positionDropdown();
28072826
} else {

0 commit comments

Comments
 (0)