Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put google places pac-container inside div?

I am using the google places autocomplete api and when I initialize the auto complete element autocomplete = new google.maps.places.Autocomplete($('#google_places_ac')[0], {}) it appends the .pac-container to the body.

I have a div that is scrollable that this content is in so what happens is the .pac-container is positioned absolute and when the div scrolls it does not scroll with it.

Is there any way I can get the .pac-container to be inserted inside of my div and not at the end of the body?

like image 968
jakecraige Avatar asked Feb 10 '14 23:02

jakecraige


1 Answers

It's not a perfect solution but it the best I could find

var addressInputElement = $('#yourInputElementId');
addressInputElement.on('focus', function () {
  var pacContainer = $('.pac-container');
  $(addressInputElement.parent()).append(pacContainer);
})

you might be needed to change some css as well

.pac-container {  
  z-index: 9999999 !important;  
  top: 32px !important;   //your input height
  left: 0 !important; 
}
like image 67
Hai Avatar answered Oct 29 '22 19:10

Hai