ubilabs / geocomplete

jQuery Geocoding and Places Autocomplete Plugin
http://ubilabs.github.com/geocomplete/
MIT License
1.22k stars 406 forks source link

Uncaught TypeError: Cannot read property 'cities' of undefined #293

Open Jirka1111 opened 8 years ago

Jirka1111 commented 8 years ago

Hello, I am using this plugin in Rails but still have a problem with error in title.

Definition of script: script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY&libraries=places&sensor=false

Input text field: <%= f.text_field :place, id: "cities", class: "form-control cities", type: "text" %>

Javascript load:

$("cities").geocomplete(); // Option 1: Call on element. $.fn.geocomplete("cities"); // Option 2: Pass element as argument.

I have done everything as described on GitHub but still cannot get it works. If I use $("#cities").geocomplete(); the error is the same.

Please, can somebody help me?

Jirka1111 commented 8 years ago

So the solution was pretty simply (thanks Sravan from SO). First row is enough:

$("cities").geocomplete();

But be aware, this jQuery gem doesn't work in Bootstrap modal.