Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Get the Target Element? #434

Open
rdetert opened this issue Jun 10, 2020 · 2 comments
Open

How to Get the Target Element? #434

rdetert opened this issue Jun 10, 2020 · 2 comments

Comments

@rdetert
Copy link

rdetert commented Jun 10, 2020

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
Copy link

@andyg2
Copy link

andyg2 commented Nov 23, 2021

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()
      },
    });
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants