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

Manage placeholder #856

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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