From 8e8b1ad03df4f1e723cb58696ebace642fce3946 Mon Sep 17 00:00:00 2001 From: Nirav Sanghani Date: Mon, 16 Apr 2012 17:05:35 -0700 Subject: [PATCH 1/3] Allow updater function (updates the value of the input field) to be overridden. --- js/bootstrap-typeahead.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index 526cf320c3..4c562f7536 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -32,6 +32,7 @@ this.matcher = this.options.matcher || this.matcher this.sorter = this.options.sorter || this.sorter this.highlighter = this.options.highlighter || this.highlighter + this.updater = this.options.updater || this.updater this.$menu = $(this.options.menu).appendTo('body') this.source = this.options.source this.shown = false @@ -45,11 +46,15 @@ , select: function () { var val = this.$menu.find('.active').attr('data-value') this.$element - .val(val) + .val(this.updater(val)) .change() return this.hide() } + , updater: function (item) { + return item + } + , show: function () { var pos = $.extend({}, this.$element.offset(), { height: this.$element[0].offsetHeight From d5a95315eb2aac641d3a28de9f92f75e56813149 Mon Sep 17 00:00:00 2001 From: Nirav Sanghani Date: Mon, 16 Apr 2012 17:24:51 -0700 Subject: [PATCH 2/3] Update typeahead docs to reflect new option. --- docs/javascript.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/javascript.html b/docs/javascript.html index 7ad42ae81f..b6f7ce92e1 100644 --- a/docs/javascript.html +++ b/docs/javascript.html @@ -1490,6 +1490,12 @@ $('.carousel').carousel({ highlights all default matches Method used to highlight autocomplete results. Accepts a single argument item and has the scope of the typeahead instance. Should return html. + + updater + function + updates input with selection + Method used to update input contents. Accepts a single argument item and has the scope of the typeahead instance. Should return a string. + From 031fa47f68f5655bf68f0c9ebf551f92028bf5d8 Mon Sep 17 00:00:00 2001 From: Nirav Sanghani Date: Mon, 16 Apr 2012 17:27:34 -0700 Subject: [PATCH 3/3] Update new typeahead method docs to be a bit clearer. --- docs/javascript.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/javascript.html b/docs/javascript.html index b6f7ce92e1..2261e65b82 100644 --- a/docs/javascript.html +++ b/docs/javascript.html @@ -1493,8 +1493,8 @@ $('.carousel').carousel({ updater function - updates input with selection - Method used to update input contents. Accepts a single argument item and has the scope of the typeahead instance. Should return a string. + replaces contents of text input with typeahead selection + Method used to update contents of text input. Accepts a single argument, the item selected from the typeahead, and has the scope of the typeahead instance. Should return a string.