Merge pull request #1604 from jdecuyper/feature-next-search-term
Add 'nextSearchTerm' function
This commit is contained in:
commit
00ba1bddfa
19
select2.js
19
select2.js
@ -694,7 +694,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
||||
this.dropdown = this.container.find(".select2-drop");
|
||||
this.dropdown.addClass(evaluate(opts.dropdownCssClass));
|
||||
this.dropdown.data("select2", this);
|
||||
|
||||
|
||||
syncCssClasses(this.dropdown, this.opts.element, this.opts.adaptDropdownCssClass);
|
||||
|
||||
this.results = results = this.container.find(resultsSelector);
|
||||
@ -775,6 +775,8 @@ the specific language governing permissions and limitations under the Apache Lic
|
||||
this.autofocus = opts.element.prop("autofocus");
|
||||
opts.element.prop("autofocus", false);
|
||||
if (this.autofocus) this.focus();
|
||||
|
||||
this.nextSearchTerm = undefined;
|
||||
},
|
||||
|
||||
// abstract
|
||||
@ -1822,7 +1824,16 @@ the specific language governing permissions and limitations under the Apache Lic
|
||||
len = this.search.val().length;
|
||||
el.setSelectionRange(len, len);
|
||||
}
|
||||
|
||||
|
||||
// initializes search's value with nextSearchTerm (if defined by user)
|
||||
// ignore nextSearchTerm if the dropdown is opened by the user pressing a letter
|
||||
if(this.search.val() === "") {
|
||||
if(this.nextSearchTerm != undefined){
|
||||
this.search.val(this.nextSearchTerm);
|
||||
this.search.select();
|
||||
}
|
||||
}
|
||||
|
||||
this.focusser.prop("disabled", true).val("");
|
||||
this.updateResults(true);
|
||||
this.opts.element.trigger($.Event("select2-open"));
|
||||
@ -2201,6 +2212,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
||||
|
||||
this.opts.element.trigger({ type: "select2-selected", val: this.id(data), choice: data });
|
||||
|
||||
this.nextSearchTerm=this.opts.nextSearchTerm(data, data.text);
|
||||
this.close();
|
||||
|
||||
if (!options || !options.noFocus)
|
||||
@ -3167,7 +3179,8 @@ the specific language governing permissions and limitations under the Apache Lic
|
||||
blurOnChange: false,
|
||||
selectOnBlur: false,
|
||||
adaptContainerCssClass: function(c) { return c; },
|
||||
adaptDropdownCssClass: function(c) { return null; }
|
||||
adaptDropdownCssClass: function(c) { return null; },
|
||||
nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; }
|
||||
};
|
||||
|
||||
$.fn.select2.ajaxDefaults = {
|
||||
|
Loading…
Reference in New Issue
Block a user