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

Commit

Permalink
Support paste input
Browse files Browse the repository at this point in the history
  • Loading branch information
hrobertson committed Jul 25, 2017
1 parent 52506cb commit f55c821
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/bootstrap-tagsinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
maxTags: undefined,
maxChars: undefined,
confirmKeys: ['Enter', ','],
confirmOnPaste: false,
deleteKeys: ['Backspace', 'Delete'],
delimiter: ',',
delimiterRegex: null,
Expand Down Expand Up @@ -396,7 +397,7 @@
},
});

self.$container.on('keydown', 'input', $.proxy(function(event) {
self.$container.on('keydown input', 'input', $.proxy(function(event) {
var $input = $(event.target),
$inputWrapper = self.findInputWrapper();

Expand Down Expand Up @@ -459,7 +460,7 @@
$input.attr('size', Math.max(this.inputSize, $input.val().length));
}, self));

self.$container.on('keypress', 'input', $.proxy(function(event) {
self.$container.on('keypress input', 'input', $.proxy(function(event) {
var $input = $(event.target);

if (self.$element.attr('disabled')) {
Expand All @@ -469,7 +470,7 @@

var text = $input.val(),
maxLengthReached = self.options.maxChars && text.length >= self.options.maxChars;
if (self.options.freeInput && (keyInList(event, self.options.confirmKeys) || maxLengthReached)) {
if (self.options.freeInput && (keyInList(event, self.options.confirmKeys) || (self.options.confirmOnPaste && event.originalEvent.type === 'input') || maxLengthReached)) {
// Only attempt to add a tag if there is data in the field
if (text.length !== 0) {
self.add(maxLengthReached ? text.substr(0, self.options.maxChars) : text);
Expand Down

0 comments on commit f55c821

Please sign in to comment.