From 78be6f0f8974bb6840ec848667c5c3d7d162620a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kari=20S=C3=B6derholm?= Date: Mon, 28 Jul 2014 17:39:26 +0300 Subject: [PATCH 1/3] Add support for form reset functionality. Tokens are now automatically updated after form reset to reflect the new input value after reset. --- js/bootstrap-tokenfield.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/bootstrap-tokenfield.js b/js/bootstrap-tokenfield.js index fc37315..c35df93 100644 --- a/js/bootstrap-tokenfield.js +++ b/js/bootstrap-tokenfield.js @@ -94,6 +94,15 @@ .css(hidingPosition, '-10000px') .prop('tabindex', -1) + // Update tokens on form reset + // Update tokens on form reset + this.$element.closest('form').on('reset', function (e) { + // Set a timeout to run code after the reset event is finished + window.setTimeout(function(){ + _self.setTokens(_self.$element.val(), false, false) + }, 0); + }) + // Create a wrapper this.$wrapper = $('
') if (this.$element.hasClass('input-lg')) this.$wrapper.addClass('input-lg') From 8a557de16a44b0cbfed9427f197c4124344588d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kari=20S=C3=B6derholm?= Date: Tue, 29 Jul 2014 10:08:49 +0300 Subject: [PATCH 2/3] Remove accidentally duplicated comment line. --- js/bootstrap-tokenfield.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/bootstrap-tokenfield.js b/js/bootstrap-tokenfield.js index c35df93..cfe8dfb 100644 --- a/js/bootstrap-tokenfield.js +++ b/js/bootstrap-tokenfield.js @@ -94,7 +94,6 @@ .css(hidingPosition, '-10000px') .prop('tabindex', -1) - // Update tokens on form reset // Update tokens on form reset this.$element.closest('form').on('reset', function (e) { // Set a timeout to run code after the reset event is finished From a1d4f57bb2cb87d4a40eef96ab29afd9d3b6951a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kari=20S=C3=B6derholm?= Date: Tue, 29 Jul 2014 16:56:48 +0300 Subject: [PATCH 3/3] Fix: Reset didn't work properly with empty default value. --- js/bootstrap-tokenfield.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/bootstrap-tokenfield.js b/js/bootstrap-tokenfield.js index cfe8dfb..298571e 100644 --- a/js/bootstrap-tokenfield.js +++ b/js/bootstrap-tokenfield.js @@ -98,7 +98,10 @@ this.$element.closest('form').on('reset', function (e) { // Set a timeout to run code after the reset event is finished window.setTimeout(function(){ - _self.setTokens(_self.$element.val(), false, false) + var newValue = _self.$element.val(); + // Convert empty string to empty array because setTokens() ignores falsy values (like empty string) + newValue = ( newValue === '' ? [] : newValue ); + _self.setTokens(newValue, false, false) }, 0); })