1
0
mirror of synced 2024-11-22 21:16:10 +03:00

Merge pull request #1604 from jdecuyper/feature-next-search-term

Add 'nextSearchTerm' function
This commit is contained in:
Igor Vaynberg 2013-08-09 16:37:01 -07:00
commit 00ba1bddfa

View File

@ -775,6 +775,8 @@ the specific language governing permissions and limitations under the Apache Lic
this.autofocus = opts.element.prop("autofocus"); this.autofocus = opts.element.prop("autofocus");
opts.element.prop("autofocus", false); opts.element.prop("autofocus", false);
if (this.autofocus) this.focus(); if (this.autofocus) this.focus();
this.nextSearchTerm = undefined;
}, },
// abstract // abstract
@ -1823,6 +1825,15 @@ the specific language governing permissions and limitations under the Apache Lic
el.setSelectionRange(len, len); 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.focusser.prop("disabled", true).val("");
this.updateResults(true); this.updateResults(true);
this.opts.element.trigger($.Event("select2-open")); 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.opts.element.trigger({ type: "select2-selected", val: this.id(data), choice: data });
this.nextSearchTerm=this.opts.nextSearchTerm(data, data.text);
this.close(); this.close();
if (!options || !options.noFocus) if (!options || !options.noFocus)
@ -3167,7 +3179,8 @@ the specific language governing permissions and limitations under the Apache Lic
blurOnChange: false, blurOnChange: false,
selectOnBlur: false, selectOnBlur: false,
adaptContainerCssClass: function(c) { return c; }, adaptContainerCssClass: function(c) { return c; },
adaptDropdownCssClass: function(c) { return null; } adaptDropdownCssClass: function(c) { return null; },
nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; }
}; };
$.fn.select2.ajaxDefaults = { $.fn.select2.ajaxDefaults = {