|
435 | 435 | prepareOpts: function (opts) { |
436 | 436 | var element, select, idKey; |
437 | 437 |
|
| 438 | + element = opts.element; |
| 439 | + |
| 440 | + if (element.get(0).tagName.toLowerCase() === "select") { |
| 441 | + this.select = select = opts.element; |
| 442 | + } |
| 443 | + |
| 444 | + if (select) { |
| 445 | + // these options are not allowed when attached to a select because they are picked up off the element itself |
| 446 | + $.each(["id", "multiple", "ajax", "query", "createSearchChoice", "initSelection", "data", "tags"], function () { |
| 447 | + if (this in opts) { |
| 448 | + throw new Error("Option '" + this + "' is not allowed for Select2 when attached to a <select> element."); |
| 449 | + } |
| 450 | + }); |
| 451 | + } |
| 452 | + |
438 | 453 | opts = $.extend({}, { |
439 | 454 | formatResult: function (data) { return data.text; }, |
440 | 455 | formatSelection: function (data) { return data.text; }, |
441 | 456 | formatNoMatches: function () { return "No matches found"; }, |
442 | 457 | formatInputTooShort: function (input, min) { return "Please enter " + (min - input.length) + " more characters"; }, |
443 | 458 | minimumResultsForSearch: 0, |
| 459 | + minimumInputLength: 0, |
444 | 460 | id: function (e) { return e.id; } |
445 | 461 | }, opts); |
446 | 462 |
|
447 | 463 | if (typeof(opts.id) !== "function") { |
448 | 464 | idKey = opts.id; |
449 | | - opts.id = function (e) { return e[idKey]; } |
450 | | - } |
451 | | - |
452 | | - element = opts.element; |
453 | | - |
454 | | - if (element.get(0).tagName.toLowerCase() === "select") { |
455 | | - this.select = select = opts.element; |
456 | | - } |
457 | | - |
458 | | - // TODO add missing validation logic |
459 | | - if (select) { |
460 | | - /*$.each(["multiple", "ajax", "query", "minimumInputLength"], function () { |
461 | | - if (this in opts) { |
462 | | - throw "Option '" + this + "' is not allowed for Select2 when attached to a select element"; |
463 | | - } |
464 | | - });*/ |
465 | | - this.opts = opts = $.extend({}, { |
466 | | - miniumInputLength: 0 |
467 | | - }, opts); |
468 | | - } else { |
469 | | - this.opts = opts = $.extend({}, { |
470 | | - miniumInputLength: 0 |
471 | | - }, opts); |
| 465 | + opts.id = function (e) { return e[idKey]; }; |
472 | 466 | } |
473 | 467 |
|
474 | 468 | if (select) { |
|
0 commit comments