Home > Mobile >  Typeahead Bloodhound don't close the autocomplete on click
Typeahead Bloodhound don't close the autocomplete on click

Time:10-02

I have a problem that I can't solve, when I click on one of the a tags (js-follow class), a function is triggered to follow / unfollow a user, however the div that contains the auto complete suggestions closes at the slightest click, and I can't keep it open. Do you have a solution to prevent it from closing on click, while executing my function ? Thank you so much !

Here is my code :

$(document).ready(function () {
  var datas = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.whitespace,
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
      url: "",
      wildcard: "",
      filter: function (datas) {
      },
    },
  });

  datas.initialize();
  $("#tags").typeahead(
    { hint: false },
    {
      name: "datas",
      source: datas.ttAdapter(),
      display: "item",
      templates: {
        suggestion: function (item) {
          return (
            `<ul></ul>`)
          );
        },
      },
    }
  );
});

CodePudding user response:

I found the solution. For anyone who is facing this problem, here is the way to do it :

$(document).on("typeahead:beforeselect", function (event, data) { event.preventDefault(); });
  • Related