Skip to content

Commit

Permalink
feat(tagsInput): Add addOnTab option
Browse files Browse the repository at this point in the history
Add an option for the user to set if a tag should be created on pressing tab and there is some text left in it. This feature
is important because it allows a more user friendly way of adding new tabs.

Closes mbenford#233.
  • Loading branch information
topikito committed Feb 26, 2015
1 parent 315f3a2 commit 0a7ef95
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @param {boolean=} [addOnSpace=false] Flag indicating that a new tag will be added on pressing the SPACE key.
* @param {boolean=} [addOnComma=true] Flag indicating that a new tag will be added on pressing the COMMA key.
* @param {boolean=} [addOnBlur=true] Flag indicating that a new tag will be added when the input field loses focus.
* @param {boolean=} [addOnTab=false] Flag indicating that a new tag will be added on pressing the TAB key.
* @param {boolean=} [addOnPaste=false] Flag indicating that the text pasted into the input field will be split into tags.
* @param {string=} [pasteSplitPattern=,] Regular expression used to split the pasted text into tags.
* @param {boolean=} [replaceSpacesWithDashes=true] Flag indicating that spaces will be replaced with dashes.
Expand Down Expand Up @@ -143,6 +144,7 @@ tagsInput.directive('tagsInput', function($timeout, $document, tagsInputConfig)
addOnSpace: [Boolean, false],
addOnComma: [Boolean, true],
addOnBlur: [Boolean, true],
addOnTab: [Boolean, false],
addOnPaste: [Boolean, false],
pasteSplitPattern: [RegExp, /,/],
allowedTagsPattern: [RegExp, /.+/],
Expand Down Expand Up @@ -184,7 +186,7 @@ tagsInput.directive('tagsInput', function($timeout, $document, tagsInputConfig)
};
},
link: function(scope, element, attrs, ngModelCtrl) {
var hotkeys = [KEYS.enter, KEYS.comma, KEYS.space, KEYS.backspace],
var hotkeys = [KEYS.enter, KEYS.comma, KEYS.space, KEYS.backspace, KEYS.tab],
tagList = scope.tagList,
events = scope.events,
options = scope.options,
Expand Down Expand Up @@ -304,6 +306,7 @@ tagsInput.directive('tagsInput', function($timeout, $document, tagsInputConfig)
addKeys[KEYS.enter] = options.addOnEnter;
addKeys[KEYS.comma] = options.addOnComma;
addKeys[KEYS.space] = options.addOnSpace;
addKeys[KEYS.tab] = options.addOnTab && scope.newTag.text.length !== 0;

shouldAdd = !options.addFromAutocompleteOnly && addKeys[key];
shouldRemove = !shouldAdd && key === KEYS.backspace && scope.newTag.text.length === 0;
Expand Down

0 comments on commit 0a7ef95

Please sign in to comment.