The Twitter Bootstraps Typeahead is a very nice way to provide autocomplete functionality on your text inputs. However, the default configuration might be a bit confusing. When the user clicks on a suggestion in the dropdown menu, the utility populates the input but doesn’t submit the form. It’s usually ok, but sometimes (e.g: search boxes) it’s frustrating. Here’s how to change it:

1
2
3
4
5
6
7
8
9
var input = $('#your-input-box');
input.typeahead({
    'source' : ['foo', 'bar', 'baz'],
    'updater' : function(item) {
        this.$element[0].value = item;
        this.$element[0].form.submit();
        return item;
    }
});

This snippet autosubmits the form if the user clicks on a suggestion or selects it by keyboard.