Skip to content

Commit

Permalink
Added new option: maxChars.
Browse files Browse the repository at this point in the history
  • Loading branch information
macseed committed Nov 27, 2013
1 parent d9f3b34 commit ad6dca9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/bootstrap-tagsinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
freeInput: true,
maxTags: undefined,
maxChars: 0,
confirmKeys: [13],
onTagExists: function(item, $tag) {
$tag.hide().fadeIn();
Expand Down Expand Up @@ -335,10 +336,12 @@
}
break;
default:
// When key corresponds one of the confirmKeys, add current input
// as a new tag
if (self.options.freeInput && keyCombinationInList(event, self.options.confirmKeys)) {
self.add($input.val());
// When key corresponds one of the confirmKeys, or text.length reached maximum,
// add current input as a new tag
var text = $input.val(),
maxLengthReached = self.options.maxChars > 0 && text.length >= self.options.maxChars;
if (self.options.freeInput && (keyCombinationInList(event, self.options.confirmKeys) || maxLengthReached)) {
self.add(maxLengthReached ? text.substr(0, self.options.maxChars) : text);
$input.val('');
event.preventDefault();
}
Expand Down

0 comments on commit ad6dca9

Please sign in to comment.