pawelczak / EasyAutocomplete

JQuery autocomplete plugin
http://easyautocomplete.com
MIT License
729 stars 244 forks source link

How to Get the Target Element? #434

Open rdetert opened 4 years ago

rdetert commented 4 years ago

I'd like to get the text field that is being triggered so I can check for some other form fields to pass in to the AJAX request.

For example,

  $('*[data-behavior="autocomplete"]').easyAutocomplete({
      url: function(term) {
        var type = $(this).siblings('[name=type]').first().val();  // doesn't work
        return "/search/autocomplete.json?q=" + term + "&type=" + type;
      },

Is it possible?

cogniti75 commented 3 years ago

Here is the answer: https://stackoverflow.com/questions/38672980/how-to-get-element-triggering-the-easyautocomplete

andyg2 commented 2 years ago

Here's one way to do it.

  $("*[data-behavior="autocomplete"]").each(function(){
    var that = $(this);
    that.AutoComplete({
      url: function () {
         that.siblings('[name=type]').first().val()
      },
    });
  });