Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable autofill/autocomplete with angular form and chrome

I have a simple form where I need disable autofill/autocomplete with angular form.

I have search on StackOverflow, but I didn´t find a solution.

I have used autocomplete="off" or autocomplete="false" but the autocomplete is never disabled.

Sometimes the autocomplete is disabled temporarily when I load a page. But, after some time after, when I reload the page the problem appears again.

enter image description here

//markup from image above

<input type="text" class="form-control input-lg ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched" capitalize-full="" ng-model="user.ENDERECO" required="" placeholder="Digite seu endereço" autocomplete="off" name="street" style="opacity: 1; text-transform: uppercase;">

//markup sample

<form class="form form-horizontal" name="regForm" 
              autocomplete="false" novalidate role="form">
 <input  type="text" class="form-control input-lg"                           
  name="cpf" ng-model="user.CPF" placeholder="Digite seu CPF" 
   required autocomplete="false" >
</form>
like image 785
Luiz Alves Avatar asked Jan 03 '18 20:01

Luiz Alves


People also ask

Is there a way to disable Chrome autofill option for angular form fields?

I managed to disable autofill on Chrome by setting any meaningless value for autocomplete . For instance autocomplete="no" .

How do I turn off autocomplete in forms?

Add autocomplete="off" onto <form> element; Add hidden <input> with autocomplete="false" as a first children element of the form.

How do I turn off auto fill in HTML?

Use the <input> tag with autocomplete attribute. Set the autocomplete attribute to value “off”.


3 Answers

In April 2018: Setting autocomplete="off" on the form itself worked for me (tested on Chrome). Setting this attribute on individual elements did not work.

like image 118
Suparna Gharpure Avatar answered Sep 24 '22 16:09

Suparna Gharpure


Simply put autocomplete="new-feildName" on html control

Example :

 <input class="signup-input-field-01" autocomplete="new-phone" 
            formControlName="phone" name="phone" type="text">
like image 21
Sandeep Patel Avatar answered Sep 21 '22 16:09

Sandeep Patel


The autocomplete="off" is effectively respected by Chrome, but what you're experiencing is the Chrome autofill functionality that takes over, ignoring autocomplete="off": https://developers.google.com/web/updates/2015/06/checkout-faster-with-autofill.

In the past, many developers would add autocomplete="off" to their form fields to prevent the browser from performing any kind of autocomplete functionality. While Chrome will still respect this tag for autocomplete data, it will not respect it for autofill data.

I did some test and from what I see here Chrome igonores the autocomplete="off" when it can map the fieldname to one of it's autofill properties. This will work <input type="text" name="somethingAutofillDoesntKnow" autocomplete="off" />, but for this fieldName Autofill will show up <input type="text" name="firstName" autocomplete="off" />.

One workaround is to put an unknown value in the autocomplete, e.g. autocomplete="doNotAutoComplete". When testing this it worked for me most of the time, but for some reason didn't work anymore afterwards.

My advise is not to fight against it and use it's potential by properly using the autocomplete attribute as explained here: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill

like image 44
Chris Aelbrecht Avatar answered Sep 20 '22 16:09

Chris Aelbrecht