twitter / typeahead.js

typeahead.js is a fast and fully-featured autocomplete library
http://twitter.github.io/typeahead.js/
MIT License
16.52k stars 3.21k forks source link

Custom event not triggered #1776

Open luisalmeida12 opened 4 years ago

luisalmeida12 commented 4 years ago

I'm trying to trigger a custom event like:

typeahead:select but nothing happens. my code is listing the info I want but then when i select nothing happens. What am I doing wrong?

var route = "autocomplete";
    $('.clientName').typeahead({
        minLength: 1,
        highlight: true,
        source:  function (term, process) {
          return $.get(route, { term: term }, function (data) {
                return process(data);
            });
        }

    });

    $('.clientName').on('typeahead:select', function(ev, suggestion) {
      alert("here");
      console.log('Selection: ' + suggestion);
  });
elzix commented 4 years ago

+1

Console logs nothing when I use (from docs)

jQuery('.typeahead').bind('typeahead:select', function(ev, suggestion) {
  console.log('Selection: ' + suggestion);
});
jQuery('.hotel_name').bind('typeahead:select', function(ev, suggestion) {
  console.log('Selection: ' + suggestion);
});

Console logs undefined when I try to add in definition:

jQuery('.hotel_name').typeahead({
  source: function (query, result) {
    jQuery.ajax({ ... });
  },
  select: function (ev, suggestion) {
    console.log('Selection: ' + suggestion);
  }
});

What are we missing?

luisalmeida12 commented 4 years ago

@elzix looks this is not being supported. :/

Canyoneer commented 4 years ago

The events were changed with version 0.11.0. You are probably using an older version. In 0.10.5 typeahead:select is typeahead:selected and typeahead:open is typeahead:opened.

This should be in the documentation, but it would probably be better to switch to a supported fork.