xcash / bootstrap-autocomplete

Bootstrap Autocomplete
MIT License
168 stars 72 forks source link

AutoComplete does not work on cloned elements #91

Closed ddashwood closed 3 years ago

ddashwood commented 3 years ago

I have a \<div> which contains a template for a part of a form. I use JQuery to dynamically clone this \<div> and add it into the form.

One of the \<input> elements of the \<div> requires auto-completion. I've noticed that when I call JQuery's clone() method and set the withDataAndEvents parameter to true, although I can see in the developer tools that the cloned \<input> has an event which is attached to the AutoComplete library, the auto-completions do not work.

Is it possible to make the library work with clone()?

As an alternative, is it possible to make a call to the library after using clone() so that it can attach itself to the latest DOM correctly?

Thank you!

xcash commented 3 years ago

No this is not possible. When the autocomplete initializes itself it creates custom elements and make some internal bindings not cloned by jQuery.

Can't you just call an initialization just after the cloning? Even if the elements shares the same classes you could scope the initialization with something like:

clonedElements.find('.autoCompleteClass').autoComplete(...)