From cefe7014037cc6679f04e14ad2051f7dffd35937 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 9 Nov 2014 21:41:23 +0100 Subject: [PATCH] Fixed tag input adding empty implications --- public_html/js/Controls/TagInput.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/public_html/js/Controls/TagInput.js b/public_html/js/Controls/TagInput.js index e944f40a..42a7c82d 100644 --- a/public_html/js/Controls/TagInput.js +++ b/public_html/js/Controls/TagInput.js @@ -121,13 +121,19 @@ App.Controls.TagInput = function($underlyingInput) { } }); + function explodeText(text) { + return _.filter(text.trim().split(/\s+/), function(item) { + return item.length > 0; + }); + } + function processText(text, callback) { - var tagNamesToAdd = text.split(/\s+/); + var tagNamesToAdd = explodeText(text); _.map(tagNamesToAdd, function(tagName) { callback(tagName); }); } function processTextWithoutLast(text, callback) { - var tagNamesToAdd = text.split(/\s+/); + var tagNamesToAdd = explodeText(text); var lastTagName = tagNamesToAdd.pop(); _.map(tagNamesToAdd, function(tagName) { callback(tagName); }); $input.val(lastTagName);