Selaa lähdekoodia

Add the ability to specify custom tags separator.

Signed-off-by: Igor Vaynberg <[email protected]>
Grzegorz Kaczan 13 vuotta sitten
vanhempi
commit
5aae33d789
1 muutettua tiedostoa jossa 6 lisäystä ja 3 poistoa
  1. 6 3
      select2.js

+ 6 - 3
select2.js

@@ -534,6 +534,9 @@
                 this.select = select = opts.element;
                 this.select = select = opts.element;
             }
             }
 
 
+            //Custom tags separator.
+            opts.tagSeparator = opts.tagSeparator || ",";
+            
             if (select) {
             if (select) {
                 // these options are not allowed when attached to a select because they are picked up off the element itself
                 // these options are not allowed when attached to a select because they are picked up off the element itself
                 $.each(["id", "multiple", "ajax", "query", "createSearchChoice", "initSelection", "data", "tags"], function () {
                 $.each(["id", "multiple", "ajax", "query", "createSearchChoice", "initSelection", "data", "tags"], function () {
@@ -663,7 +666,7 @@
                         opts.createSearchChoice = function (term) { return {id: term, text: term}; };
                         opts.createSearchChoice = function (term) { return {id: term, text: term}; };
                         opts.initSelection = function (element, callback) {
                         opts.initSelection = function (element, callback) {
                             var data = [];
                             var data = [];
-                            $(splitVal(element.val(), ",")).each(function () {
+                            $(splitVal(element.val(), opts.tagSeparator)).each(function () {
                                 data.push({id: this, text: this});
                                 data.push({id: this, text: this});
                             });
                             });
 
 
@@ -1467,7 +1470,7 @@
             opts = $.extend({}, {
             opts = $.extend({}, {
                 closeOnSelect: true
                 closeOnSelect: true
             }, opts);
             }, opts);
-
+            
             // TODO validate placeholder is a string if specified
             // TODO validate placeholder is a string if specified
 
 
             if (opts.element.get(0).tagName.toLowerCase() === "select") {
             if (opts.element.get(0).tagName.toLowerCase() === "select") {
@@ -1827,7 +1830,7 @@
                 return val === null ? [] : val;
                 return val === null ? [] : val;
             } else {
             } else {
                 val = this.opts.element.val();
                 val = this.opts.element.val();
-                return splitVal(val, ",");
+                return splitVal(val, this.opts.tagSeparator);
             }
             }
         },
         },