Skip to content

Commit b1867b5

Browse files
committed
fix access to search method. fixes select2#1392
1 parent 4917429 commit b1867b5

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

select2.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ the specific language governing permissions and limitations under the Apache Lic
13431343
* Opens control, sets input value, and updates results.
13441344
*/
13451345
// abstract
1346-
search: function (term) {
1346+
externalSearch: function (term) {
13471347
this.open();
13481348
this.search.val(term);
13491349
this.updateResults(false);
@@ -3033,9 +3033,10 @@ the specific language governing permissions and limitations under the Apache Lic
30333033
var args = Array.prototype.slice.call(arguments, 0),
30343034
opts,
30353035
select2,
3036-
value, multiple,
3036+
method, value, multiple,
30373037
allowedMethods = ["val", "destroy", "opened", "open", "close", "focus", "isFocused", "container", "dropdown", "onSortStart", "onSortEnd", "enable", "readonly", "positionDropdown", "data", "search"],
3038-
valueMethods = ["val", "opened", "isFocused", "container", "data"];
3038+
valueMethods = ["val", "opened", "isFocused", "container", "data"],
3039+
methodsMap = { search: "externalSearch" };
30393040

30403041
this.each(function () {
30413042
if (args.length === 0 || typeof(args[0]) === "object") {
@@ -3060,12 +3061,17 @@ the specific language governing permissions and limitations under the Apache Lic
30603061
value = undefined;
30613062
select2 = $(this).data("select2");
30623063
if (select2 === undefined) return;
3063-
if (args[0] === "container") {
3064+
3065+
method=args[0];
3066+
3067+
if (method === "container") {
30643068
value = select2.container;
3065-
} else if (args[0] === "dropdown") {
3069+
} else if (method === "dropdown") {
30663070
value = select2.dropdown;
30673071
} else {
3068-
value = select2[args[0]].apply(select2, args.slice(1));
3072+
if (methodsMap[method]) method = methodsMap[method];
3073+
3074+
value = select2[method].apply(select2, args.slice(1));
30693075
}
30703076
if (indexOf(args[0], valueMethods) >= 0) {
30713077
return false;

0 commit comments

Comments
 (0)