Submit selection on Bootstrap typeahead() autocomplete?

Nathan Waters picture Nathan Waters · Feb 24, 2012 · Viewed 19.5k times · Source

How do I autosubmit the selection made with Twitter Bootstrap typeahead()??

http://twitter.github.com/bootstrap/javascript.html#typeahead

Answer

erenon picture erenon · Mar 2, 2013

There is a clean way using the updater callback:

input.typeahead({
    'source' : ['foo', 'bar'],
    'updater' : function(item) {
        this.$element[0].value = item;
        this.$element[0].form.submit();
        return item;
    }
});

When user selects an option (either by mouse click or keyboard), the callback populates the input box and sends the form.