oakmac / autocompletejs

AutoCompleteJS Widget
Other
72 stars 14 forks source link

I need AutoComplete help!! #80

Closed MajorKusinagi closed 10 years ago

MajorKusinagi commented 10 years ago

Hi!

I am currently trying to use this lovely autoComplete widget for a big javascript project I'm working on. I set up 2 autoCompletes on a form and it was easy and they work well.

However, can someone tell me how to get a reference to a created autoComplete widget in the DOM when I don't have a handle on it already and it is not in scope?

All of the examples on the website show you creating the widget then using functions on the widget below so you have the ref. to the widget already. What if I'm in a different function and I want to call getValue() on an autocomplete? How do I access the autocomplete to call getValue()?

Thanks, Frank frank.policastro@gmail.com

oakmac commented 10 years ago

This is more of a JavaScript scope question than an autocomplete.js question.

autocomplete.js returns a JavaScript object that you'll need in order interact with the widget.

I'm not familiar with how your code is structured so I can't offer an exact fix, but maybe try storing the reference to the widget at a higher level?

One idea is to put the reference in the global scope:

window.MY_AUTOCOMPLETE_WIDGET1 = new AutoComplete('div1', opts);

Sounds like you're trying to use the value of the widget when it gets updated; maybe assign something to your onChange function that is in the scope you need?

MajorKusinagi commented 10 years ago

Thank you very much. I will go with that. I was just wondering if there was a function similar to {menuObject}.selectmenu(); like in some other jquery plugins that would give you back a reference to the whole autocomplete widget and I was missing it. I am new to javascript development on this level...I'm coming from an asp.net background so I am accustom to only using javascript to enable and disable fields ha ha. Thanks!