From 7740f39ed7d1a320336c4438e8f3156ce40f529d Mon Sep 17 00:00:00 2001 From: Jonathan Marshall Date: Wed, 8 Oct 2014 21:47:06 +0200 Subject: [PATCH] Make sure to display the correct label. If a form is submitted and the user navigates back to the page, the value would be displayed instead of the label. This resolves the issue by submitting the value to Typeahead which then returns the correct values. --- js/bootstrap-tokenfield.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/js/bootstrap-tokenfield.js b/js/bootstrap-tokenfield.js index 770e476..8f4bea2 100644 --- a/js/bootstrap-tokenfield.js +++ b/js/bootstrap-tokenfield.js @@ -335,8 +335,17 @@ } var _self = this + var typeaheadOptions = this.options.typeahead[1] + $.each(tokens, function (i, attrs) { - _self.createToken(attrs, triggerChange) + if ( ! $.isEmptyObject( typeaheadOptions ) ) { + typeaheadOptions.source(attrs, function(value) { + _self.createToken(value[0], triggerChange) + }); + } + else { + _self.createToken(attrs, triggerChange) + } }) return this.$element.get(0)