Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Autofill covers Autocomplete for Google Maps API v3

I am using Google Maps Javascript v3 to setup autocomplete on an HTML input field like so:

http://imgur.com/Rm6X2FI.png - (w/out autofill)

The issue I'm having is that Chrome's Autofill covers up the Maps Autocomplete like this:

http://imgur.com/7a2QM7L.png - (w/ autofill)

I found a solution online a couple of months ago (ref: Disabling Chrome Autofill), but it seems that this solution no longer has any effect.

<input type="text" name="address" id="address_fake" autocomplete="off" style="display:none"> <input type="text" name="address" id="address" autocomplete="off" placeholder="Address" /> 

Is there any way I can stop Chrome's Autofill from showing on top of the Google Maps Autocomplete list?

EDIT: Stop Google chrome auto fill the input does not provide a solution to my current issue. The issue is with the Chrome Autofill dropdown on the input field, not the input field being automatically filled with an autofill value.

like image 557
Cole Waldrip Avatar asked Apr 28 '15 23:04

Cole Waldrip


People also ask

Where is Googlecom autocomplete API key?

You need to go your project. 1: Activate Google places API depending upon your clients: iOS, Android or web. 2: Then go to the Credentials section on the left. 3: Generate a SERVER key.

What triggers Chrome Autofill?

In order to trigger autocomplete, make sure you correctly name the name and autocomplete attributes in your <input> tags. This will automatically allow for autocomplete on forms. Make sure also to have a <label> ! This information can also be found here.


1 Answers

None of the above answers worked for me (Chrome 64.0.3282.186, x64 windows).

TL;DR: The Google Maps code is changing the autocomplete attribute to off, so even if you set it to new-password, you'll still get autofill. The hack I'm using is to listen for mutations on that attribute and then override it. Note: simply changing the attribute after calling into Google Maps does not work.

Set up a MutationObserver before initializing Google Maps Autocomplete that immediately stops listening for mutations and then sets the attribute to new-password.

    var autocompleteInput = document.getElementById("id-of-element");      var observerHack = new MutationObserver(function() {         observerHack.disconnect();         $("#id-of-element").attr("autocomplete", "new-password");     });      observerHack.observe(autocompleteInput, {         attributes: true,         attributeFilter: ['autocomplete']     }); 
like image 174
Rimmel Avatar answered Sep 29 '22 01:09

Rimmel