twitter/bootstrap — Issue #1593: onItemSelected callback in typeahead
Author: stefanozoffoli
Created: 2012-02-02 11:59:12+00:00
State: open

Hi,

I use typeahead with jQuery Tags Input ( http://xoxco.com/projects/code/tagsinput/ ).

I'd like to have more control over typeahead select method, just like the matcher, sorter and highlighter, so that when the user choose an item, i can add that item to my tags list.

For now i just edited the constructor from this:

```javascript
var Typeahead = function ( element, options ) {
this.$element = $(element)
this.options = $.extend({}, $.fn.typeahead.defaults, options)
this.matcher = this.options.matcher || this.matcher
this.sorter = this.options.sorter || this.sorter
this.highlighter = this.options.highlighter || this.highlighter
this.$menu = $(this.options.menu).appendTo('body')
this.source = this.options.source
this.shown = false
this.listen()
}
```

to this:

```javascript
var Typeahead = function ( element, options ) {
this.$element = $(element)
this.options = $.extend({}, $.fn.typeahead.defaults, options)
this.matcher = this.options.matcher || this.matcher
this.sorter = this.options.sorter || this.sorter
this.highlighter = this.options.highlighter || this.highlighter
this.select = this.options.select || this.select
this.$menu = $(this.options.menu).appendTo('body')
this.source = this.options.source
this.shown = false
this.listen()
}
```

and made my own select function.
But it would be nice to have a callback like onItemSelected with the value of the item selected.