Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

Commit

Permalink
Merge e124300 into 87d0e6b
Browse files Browse the repository at this point in the history
  • Loading branch information
conraddamon committed Mar 28, 2018
2 parents 87d0e6b + e124300 commit 4ebd321
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ export default function TagsInputDirective($timeout, $document, $window, $q, tag
scope.$watch('tags.length', () => {
setElementValidity();

// show placeholder only if there are no tags and no input
input.attr('placeholder', tagList.items.length === 0 && input.val() === '' ? options.placeholder : '');

// ngModelController won't trigger validators when the model changes (because it's an array),
// so we need to do it ourselves. Unfortunately this won't trigger any registered formatter.
ngModelCtrl.$validate();
Expand Down
23 changes: 23 additions & 0 deletions test/tags-input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,29 @@ describe('tags-input directive', () => {
// Assert
expect(isolateScope.options.placeholder).toBe('Add a tag');
});

it('clears the placeholder if there is at least one tag', () => {
// Arrange
compile();

// Act
newTag('foo');

// Assert
expect(getInput().attr('placeholder')).toBe('');
});

it('restores the placeholder when there are no tags', () => {
// Arrange
compile();

// Act
newTag('foo');
getRemoveButton(0).click();

// Assert
expect(getInput().attr('placeholder')).toBe('Add a tag');
});
});

describe('remove-tag-symbol option', () => {
Expand Down

0 comments on commit 4ebd321

Please sign in to comment.