diff --git a/docs/javascript.html b/docs/javascript.html index 7ad42ae81f..2261e65b82 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 + 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. + 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