From 0bfc7ee3f40399fee5e8dfa6562dbbc3574cdbf1 Mon Sep 17 00:00:00 2001 From: Michael Benford Date: Thu, 12 Mar 2015 21:54:41 -0300 Subject: [PATCH] fix(tagsInput): Fix element validity on tag removal 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 --- src/tags-input.js | 2 +- test/tags-input.spec.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/tags-input.js b/src/tags-input.js index 50aa9857..3c07bb6d 100644 --- a/src/tags-input.js +++ b/src/tags-input.js @@ -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 = { diff --git a/test/tags-input.spec.js b/test/tags-input.spec.js index 77f43b1f..d82c9e5b 100644 --- a/test/tags-input.spec.js +++ b/test/tags-input.spec.js @@ -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"');