From 5aae33d789f7113c098f4b03f24f44fc183754e0 Mon Sep 17 00:00:00 2001 From: Grzegorz Kaczan Date: Fri, 6 Jul 2012 14:20:48 +0200 Subject: [PATCH] Add the ability to specify custom tags separator. Signed-off-by: Igor Vaynberg --- select2.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/select2.js b/select2.js index 6bc2feb4..43b3f2ec 100755 --- a/select2.js +++ b/select2.js @@ -534,6 +534,9 @@ this.select = select = opts.element; } + //Custom tags separator. + opts.tagSeparator = opts.tagSeparator || ","; + if (select) { // 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 () { @@ -663,7 +666,7 @@ opts.createSearchChoice = function (term) { return {id: term, text: term}; }; opts.initSelection = function (element, callback) { var data = []; - $(splitVal(element.val(), ",")).each(function () { + $(splitVal(element.val(), opts.tagSeparator)).each(function () { data.push({id: this, text: this}); }); @@ -1467,7 +1470,7 @@ opts = $.extend({}, { closeOnSelect: true }, opts); - + // TODO validate placeholder is a string if specified if (opts.element.get(0).tagName.toLowerCase() === "select") { @@ -1827,7 +1830,7 @@ return val === null ? [] : val; } else { val = this.opts.element.val(); - return splitVal(val, ","); + return splitVal(val, this.opts.tagSeparator); } },