Fixed tag input adding empty implications

This commit is contained in:
Marcin Kurczewski 2014-11-09 21:41:23 +01:00
parent 99845af35b
commit cefe701403

View file

@ -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) { function processText(text, callback) {
var tagNamesToAdd = text.split(/\s+/); var tagNamesToAdd = explodeText(text);
_.map(tagNamesToAdd, function(tagName) { callback(tagName); }); _.map(tagNamesToAdd, function(tagName) { callback(tagName); });
} }
function processTextWithoutLast(text, callback) { function processTextWithoutLast(text, callback) {
var tagNamesToAdd = text.split(/\s+/); var tagNamesToAdd = explodeText(text);
var lastTagName = tagNamesToAdd.pop(); var lastTagName = tagNamesToAdd.pop();
_.map(tagNamesToAdd, function(tagName) { callback(tagName); }); _.map(tagNamesToAdd, function(tagName) { callback(tagName); });
$input.val(lastTagName); $input.val(lastTagName);