Search code examples
javascripttypeahead.jsbloodhound

Avoid typeahead.js remote if regex matches


how do I avoid a server request in typeahead.js if certain regex matches? I dont't want to start a suggestion if numbers are typed in but letters should start the ajax request.

Is this possible in typeahead.js or bloodhound?

I still have version 0.10.5 as an update would affect in too many places.

best regards Eike


Solution

  • I found a solution by myself: Just return false in beforeSend.

    engine = new Bloodhound({
       ajax: {
           url: "example.com",
           beforeSend: function() {
               return null === $(<selector>).typeahead("val").match(/regexIdontWant/);
           }
       }
    });