Merge pull request #1604 from jdecuyper/feature-next-search-term
Add 'nextSearchTerm' function
This commit is contained in:
commit
00ba1bddfa
15
select2.js
15
select2.js
@ -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
|
||||
@ -1823,6 +1825,15 @@ the specific language governing permissions and limitations under the Apache Lic
|
||||
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