devbridge / jQuery-Autocomplete

Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
https://www.devbridge.com/sourcery/components/jquery-autocomplete/
Other
3.57k stars 1.67k forks source link

How do I bind this to multiple input fields with the same class name? #792

Closed crazyserb closed 4 years ago

crazyserb commented 4 years ago

I see you bind it to an element with the ID #autocomplete, but if I try to bind it to more than one input field with the same class name (say ".autocomp" for example), it doesn't work at all.

What am I missing?

Is this even possible, and how?

tkirda commented 4 years ago

This should be working. If you look at the source it is creating instance for each matched element:

https://github.com/devbridge/jQuery-Autocomplete/blob/9b30e414dd8b87e1831f9f28870b88d646f3553c/src/jquery.autocomplete.js#L977-L1002

crazyserb commented 4 years ago

It should be, but it's not... anyone tested it on their end?

If I bind it to multiple IDs, like this, it works:

$('#autocomplete1, #autocomplete2, #autocomplete3').autocomplete({...

But if I try and bind it to an unspecified number of input fields/elements (as some of the sections have variable number of these fields, and it's impossible to get the exact number and IDs for each) like this, none of them work:

$('.autocomp').autocomplete({...

tkirda commented 4 years ago

It should work unless you have overlooked something on your end.