Skip to content

Commit

Permalink
Merge 3eb976b into f84dcba
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgruber authored Apr 29, 2019
2 parents f84dcba + 3eb976b commit d1289a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/taggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@
}

values.split(delimiter).map(function(val) {
if (self.settings.trimTags) {
val = _trim(val);
}
return self._formatTag(val);
}).forEach(function(val) {
if (!self._canAdd(e, val)) {
Expand Down
22 changes: 16 additions & 6 deletions test/taggle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,10 +930,14 @@ describe('Taggle', function() {
expect(this.instance.getTagElements().length).to.equal(6);
});

it('should add new tags from a comma delimited list', function() {
it('should add and trim new tags from a comma delimited list', function() {
expect(this.instance.getTagElements().length).to.equal(4);
var tags = 'four, five, six, seven';
var allTags = this.instance.getTagValues().concat(tags.split(','));
var allTags = this.instance.getTagValues()
.concat(tags.split(','))
.map(function(tag) {
return tag.trim();
});
this.instance.add(tags);
expect(this.instance.getTagElements().length).to.equal(8);

Expand All @@ -949,7 +953,9 @@ describe('Taggle', function() {
delimeter: delimiter
});
var tags = 'four| five| six| seven';
var allTags = tags.split(delimiter);
var allTags = tags.split(delimiter).map(function(tag) {
return tag.trim();
});
instance.add(tags);
expect(instance.getTagElements().length).to.equal(allTags.length);

Expand All @@ -965,7 +971,9 @@ describe('Taggle', function() {
delimiter: delimiter
});
var tags = 'four| five| six| seven';
var allTags = tags.split(delimiter);
var allTags = tags.split(delimiter).map(function(tag) {
return tag.trim();
});
instance.add(tags);
expect(instance.getTagElements().length).to.equal(allTags.length);

Expand All @@ -975,8 +983,10 @@ describe('Taggle', function() {
});
});

it('should preserve spaces', function() {
var instance = new Taggle(this.container);
it('should preserve spaces when trim is false', function() {
var instance = new Taggle(this.container, {
trimTags: false
});
var tags = ['one ', ' two', ' three '];

instance.add(tags);
Expand Down

0 comments on commit d1289a9

Please sign in to comment.