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

Commit

Permalink
fix(tagsInput): Fix element validity on tag removal
Browse files Browse the repository at this point in the history
Fix element validity when removing a tag and there is some text in the
input field and the allowLeftoverText option is set to false.

Closes #381
  • Loading branch information
mbenford committed Mar 13, 2015
1 parent b550b11 commit 0bfc7ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ tagsInput.directive('tagsInput', function($timeout, $document, tagsInputConfig,
setElementValidity = function() {
ngModelCtrl.$setValidity('maxTags', scope.tags.length <= options.maxTags);
ngModelCtrl.$setValidity('minTags', scope.tags.length >= options.minTags);
ngModelCtrl.$setValidity('leftoverText', options.allowLeftoverText ? true : !scope.newTag.text);
ngModelCtrl.$setValidity('leftoverText', scope.hasFocus || options.allowLeftoverText ? true : !scope.newTag.text);
};

scope.newTag = {
Expand Down
16 changes: 16 additions & 0 deletions test/tags-input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,22 @@ describe('tags-input directive', function() {
expect($scope.form.tags.$error.leftoverText).toBe(false);
});

it('does not make the element invalid when some tag is removed and there is any leftover text', function() {
// Arrange
compileWithForm('allow-leftover-text="false"', 'name="tags"');
isolateScope.hasFocus = true;
newTag('foo');
newTag('Foo');
changeInputValue('some text');

// Act
getRemoveButton(0).click();

// Assert
expect($scope.form.tags.$valid).toBe(true);
expect($scope.form.tags.$error.leftoverText).toBe(false);
});

it('makes the element valid and removes the leftoverText error when it gains focus', function() {
// Arrange
compileWithForm('name="tags"');
Expand Down

0 comments on commit 0bfc7ee

Please sign in to comment.