felipep
felipep

Reputation: 2512

Bootstrap 3 typeahead.js, use similar functions from Bootstrap 2

I have updated Bootstrap 2 to Bootstrap 3, and the biggest problem is that typeahead has been removed, and it's recommended the use of typeahead.js. So I installed it, and the easy uses of typeahead work without problems, but I also use other functions like:

 $('#my_field').typeahead({
     source : [list_of_items],
     matcher: function(item) {
         foo();
         return item;
     },
     updater : function(item) {
         foo2();
         return item;
     },
     closed: function(item) {
       ...
     },
     autocompleted: function(item) {
       ...
     }
 });

How can I implement similar functions using typeahead.js?

Under https://github.com/twitter/typeahead.js are some functions like

typeahead:initialized, typeahead:opened, typeahead:closed

but there are no examples on how to use them

Upvotes: 0

Views: 3033

Answers (1)

Bass Jobsen
Bass Jobsen

Reputation: 49044

You Could also try to use the "old" plugin, see: https://github.com/bassjobsen/Bootstrap-3-Typeahead.

The typeahead:initialized etc your mention are events. You can use them to trigger some code when the event happens, like $('typeahead').on('typeahead:initialized',function()).

You could use the filter function to add functions like matcher.

When datums are rendered as suggestions, the datum object is the context passed to the template engine. This means if you include any arbitrary properties in datum objects, those properties will be available to the template used to render suggestions.

This can be use to implement the highlight function.

So you will have to differentiate between data functions, template functions and events.

Upvotes: 1

Related Questions