Skip to content

Commit

Permalink
Merge pull request twbs#3104 from iamnirav/2.0.3-wip
Browse files Browse the repository at this point in the history
Allow updater function in bootstrap-typeahead.js (updates the value of the input field) to be overridden
  • Loading branch information
fat committed Apr 17, 2012
2 parents 2881269 + 031fa47 commit ba202d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/javascript.html
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,12 @@ <h3>Options</h3>
<td>highlights all default matches</td>
<td>Method used to highlight autocomplete results. Accepts a single argument <code>item</code> and has the scope of the typeahead instance. Should return html.</td>
</tr>
<tr>
<td>updater</td>
<td>function</td>
<td>replaces contents of text input with typeahead selection</td>
<td>Method used to update contents of text input. Accepts a single argument, the <code>item</code> selected from the typeahead, and has the scope of the typeahead instance. Should return a string.</td>
</tr>
</tbody>
</table>

Expand Down
7 changes: 6 additions & 1 deletion js/bootstrap-typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ba202d7

Please sign in to comment.