From f55c821ee1faa86307719bde0ba30a6003e21fe2 Mon Sep 17 00:00:00 2001 From: Hamish Robertson Date: Tue, 25 Jul 2017 13:46:55 +0100 Subject: [PATCH] Support paste input --- src/bootstrap-tagsinput.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bootstrap-tagsinput.js b/src/bootstrap-tagsinput.js index 8ee8ed23..24ce8517 100644 --- a/src/bootstrap-tagsinput.js +++ b/src/bootstrap-tagsinput.js @@ -20,6 +20,7 @@ maxTags: undefined, maxChars: undefined, confirmKeys: ['Enter', ','], + confirmOnPaste: false, deleteKeys: ['Backspace', 'Delete'], delimiter: ',', delimiterRegex: null, @@ -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(); @@ -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')) { @@ -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);