Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typeahead.js does not trigger source function

I am trying to integrate twitter typeahead.js, for this I downloaded the library from https://github.com/twitter/typeahead.js and included typeahead.bundle.min.js

I then added the following

<input type="text" class="form-control typeahead font-normal">
$('.typeahead').typeahead({
    source: function(query, process) {
        console.log(query);
    }
});

The problem is it does trigger the source function, I am expecting that it prints the query in console. which it does not.

What could be possibly wrong here?

Thanks.

Following solution worked.

As pointed in the answer, I added the following library first

  1. jquery.min.js
  2. typeahead.bundle.min.js (https://twitter.github.io/typeahead.js/)
  3. typeahead.jquery.min.js (https://twitter.github.io/typeahead.js/)
  4. bootstrap3-typeahead.min.js (https://github.com/bassjobsen/Bootstrap-3-Typeahead)

And then initialized the following code

$('.typeahead').typeahead({
    source: function(query, process) {  
        process([
            {id: "1", name: "Display name 1"},
            {id: "2", name: "Display name 2"}
        ]);
    }
});

And it works.

like image 823
Ibrahim Azhar Armar Avatar asked Jul 19 '26 22:07

Ibrahim Azhar Armar


1 Answers

Try this, You have to add bootstrap typeahead js

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.js"></script>

jsFiddle for the same https://jsfiddle.net/aa7zyyof/17/

like image 192
Trimantra Software Solution Avatar answered Jul 21 '26 12:07

Trimantra Software Solution



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!