yuku / textcomplete

Autocomplete for HTMLTextAreaElement and more.
https://yuku.takahashi.coffee/textcomplete/
MIT License
1.74k stars 303 forks source link

Search block is not called more than once #286

Closed scaryguy closed 8 years ago

scaryguy commented 8 years ago

Hi,

First of all, I really appreciate all your effort and thank you for this cool library @yuku-t !

However, I'm unable to do what I want to do. I've been pulling my hair since hours...

I'm trying to fetch some data from a remote API and show the results at the autocomplete popup.

Here is my code:

  $('#desc_textarea').textcomplete([
      { // html
          match: /<(\w*)$/,
          search: function (term, callback) {
            console.log("coming here???");
            $.get({url: "http://localhost:3000/testing"}, function(result) {
                console.log(result);
                return callback(["one", "two", "three"])
            })
          },
          index: 1,
          replace: function (element) {
              return ['<' + element + '>', '</' + element + '>'];
          }
      }
  ]);

When I run this code and type < only the very first time it runs smoothly and without any problem. HOWEVER, when I type < for the second time, NOTHING happens. There is no error at console and nothing. search: callback is not called after the first call.

When I remove $.get request from the code, everything works fine again.

Can you please help me? Thank you!

scaryguy commented 8 years ago

Man...

I've spent more than 3 hours... Just because I haven't seen that little sentence at the README.md which is: See doc dir.!

All I had to do was calling callback(term) before making the API call...

This is a perfect library but PLEASE make documentation more visible :(