kristianmandrup/gmaps-autocomplete-rails

Multiple autocomplete fields on the same page does not autocomplete correctly

Opened this issue · 8 comments

Hi,

First, I want to say thanks for writing this great gem. It makes using gmaps autocomplete much easier, and gives me better results than other solutions.

I am currently trying to get multiple autocomplete fields on the same page, and by initializing gmaps-autocomplete with different input-field ids, it does work as intended (with respect to showing autocomplete results).

However, if you choose a result and autocomplete, it will also autocomplete all fields that occur after the chosen field (e.g. autocompleting address field 1 will fill address field 2 and 3 with the same results, autocompleting address field 2 will fill address field 3 with the same results, and autocompleting address 3 will result in the expected behavior).

I encourage you to branch off this gem. Then substitute the current JS implementation with a JS class based solution, using coffeescript. This should allow creating multiple instances of the same class and thus solve your issue. Maybe we can work on this as a team ;)

That would be interesting to do, but I am very new to web development. Any idea of how much time this would take for a novice, and would you be able to point me in the right direction for good resources to learn from?

I just pushed a partial conversion to coffescript using a class to package the functionality. You can help work on it ;)

See the update section in the readme. Check out gmaps-auto-complete.coffee

And http://arcturo.github.io/library/coffeescript/03_classes.html

Thanks, that was really fast! I've tried using it, but for some reason, I keep getting the error that GmapsCompleter is not defined. I've made sure the file is included in the source, and it compiles to exactly what you have in the assets folder, but for some reason, the method is not being found.

Just to clarify, in order to start it now, should
"$(document).ready ->
new GmapsCompleter()
#GmapsCompleter.autoCompleteInit()
return "
be included in the class coffee file? I am getting meaningful errors this way, but I'm not sure if it will lead to the expected behavior, even when everything else is made to work correctly.

I got it working. I made a pull request with a couple small changes to the coffeescript (and compiled coffeescript), and an updated readme with instructions on how to use the new class. However, I only tested it with autocomplete, so issues may still exist with the map features.

Any update on using it for multiple input fields? As per General info on this repo

The script is now compiled from Coffeescript and allows you to have multiple fields linked to multiple instances of the GmapsCompleter class on the same page.

It should work, if it is correct then please close this issue.

Please someone re-engineer this class using ES6 classes and modules. Cheers ;)