Chrome Autofill covers Autocomplete for Google Maps API v3

后端 未结 21 1084
我在风中等你
我在风中等你 2021-02-01 00:57

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

21条回答
  •  暖寄归人
    2021-02-01 01:27

    For those that are using Angularjs, I created a directive based on @Rimmel answer that is working for me in Chrome 66.0.3359.139. Below is the code:

    (function(){
      'use strict'; 
      angular.module('app.directive')
        .directive('stopAutofill', stopAutofillDirective);
    
      function stopAutofillDirective() {
          return {
            restrict: 'A',
            link: function (scope, element) {
                var observerHack = new MutationObserver(function () {
                    observerHack.disconnect();
                    element.attr("autocomplete", "new-password");
                });
    
                observerHack.observe(element[0], {
                    attributes: true,
                    attributeFilter: ['autocomplete']
                });
            }
          };
        };
    })();
    

提交回复
热议问题