bassjobsen / Bootstrap-3-Typeahead

The Typeahead plugin from Twitter's Bootstrap 2 ready to use with Bootstrap 3 and Bootstrap 4
1.68k stars 1.33k forks source link

Potential autofocus element conflict #175

Open ianmcqueen opened 8 years ago

ianmcqueen commented 8 years ago

Sometimes but not always, typeahead doesn't seem to initialize when "autofocus" is present for an input element. It works intermittently when autofocus is present in an input element (haven't tested for other element types). For example:

HTML

<input type="text" class="form-control input-lg" id="searchbox" placeholder="Type any item name..." autocomplete="off" data-provide="typeahead" autofocus>

JS

<script>
$(function () {
    $.get('/items/typeahead', function(data) {
        console.log('got the data');
        console.log(data);

        $("#searchbox").typeahead({
            minLength: 2,
            source: data,
            afterSelect: function(item)
            {
                window.location.href = '/items/'+item.slug;
            }
        });
    }, 'json');
});
</script>

When I remove "autofocus" from the input element, typeahead works every time. Not sure if there's a conflict there.

VNovotna commented 7 years ago

I have experienced similar behaviour. When there is autofocus on input, typeahead window get hidden. When the input looses focus, eg clicking anywhere else on page, everything works fine.