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

Commit

Permalink
feat(tagsInput): Add ng-required support
Browse files Browse the repository at this point in the history
Add support for the ng-required directive so the required validation key
is set when there are no tags in the model bound to the tagsInput directive.

Closes #157
  • Loading branch information
mbenford committed Mar 20, 2015
1 parent 6102176 commit 8f17b9f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ tagsInput.directive('tagsInput', function($timeout, $document, $window, tagsInpu
ngModelCtrl.$setValidity('leftoverText', scope.hasFocus || options.allowLeftoverText ? true : !scope.newTag.text);
};

ngModelCtrl.$isEmpty = function(value) {
return !value || !value.length;
};

scope.newTag = {
text: '',
invalid: null,
Expand Down
30 changes: 30 additions & 0 deletions test/tags-input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,36 @@ describe('tags-input directive', function() {
});
});

describe('ng-required support', function() {
it('sets the required validation key when there is no tags', function() {
// Arrange/Act
compileWithForm('name="tags"', 'ng-required="true"');

// Assert
expect($scope.form.tags.$invalid).toBe(true);
expect($scope.form.tags.$error.required).toBe(true);
});

it('doesn\'t set the required validation key when there is any tags', function() {
// Arrange/Act
$scope.tags = ['Tag'];
compileWithForm('name="tags"', 'ng-required="true"');

// Assert
expect($scope.form.tags.$invalid).toBe(false);
expect($scope.form.tags.$error.required).toBe(false);
});

it('doesn\'t set the required validation key when ng-required is false', function() {
// Arrange/Act
compileWithForm('name="tags"', 'ng-required="false"');

// Assert
expect($scope.form.tags.$invalid).toBe(false);
expect($scope.form.tags.$error.required).toBe(false);
});
});

describe('autocomplete registration', function() {
var autocompleteObj;

Expand Down

0 comments on commit 8f17b9f

Please sign in to comment.