From e4767c2da75ee8d197c804f15620d107495a91a4 Mon Sep 17 00:00:00 2001 From: just-boris Date: Wed, 9 Jul 2014 18:31:05 +0400 Subject: [PATCH] fix(tagsInput): Ignore addFromAutocompleteOnly on input-blur Ignore the addFromAutocompleteOnly option on the input-blur event and always set the element's validity. --- src/tags-input.js | 13 ++++--------- test/tags-input.spec.js | 12 ------------ 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/tags-input.js b/src/tags-input.js index 3542ed4c..c27cd6a8 100644 --- a/src/tags-input.js +++ b/src/tags-input.js @@ -280,19 +280,14 @@ tagsInput.directive('tagsInput', function($timeout, $document, tagsInputConfig) }) .on('input-focus', function() { element.triggerHandler('focus'); - ngModelCtrl.$setValidity('leftoverText', true); }) .on('input-blur', function() { - element.triggerHandler('blur'); - - if (!options.addFromAutocompleteOnly) { - if (options.addOnBlur) { - tagList.addText(scope.newTag.text); - } - - setElementValidity(); + if (options.addOnBlur && !options.addFromAutocompleteOnly) { + tagList.addText(scope.newTag.text); } + element.triggerHandler('blur'); + setElementValidity(); }) .on('input-keydown', function(event) { var key = event.keyCode, diff --git a/test/tags-input.spec.js b/test/tags-input.spec.js index 7d5563ca..2025cebc 100644 --- a/test/tags-input.spec.js +++ b/test/tags-input.spec.js @@ -1287,18 +1287,6 @@ describe('tags-input directive', function() { // Assert expect(isolateScope.tags).toEqual([]); }); - - it('does not make the element invalid when it loses focus and there is any leftover text', function() { - // Arrange - isolateScope.newTag.text = 'foo'; - - // Act - isolateScope.events.trigger('input-blur'); - - // Assert - expect($scope.form.tags.$valid).toBe(true); - expect($scope.form.tags.$error.leftoverText).toBeFalsy(); - }); }); });