15

I have an angular form like this

<ng-form name="AddTaskForm" autocomplete="off">
   ......
</ng-form>

However when I begin entering data, chrome is still prompting me with previously entered values.

How can I prevent chrome (and all browsers) from showing any drop down on my input with previously entered values?

I did some search and found that people were writing custom directives, but not sure if this is really required.

enter image description here

Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373

3 Answers3

24

Despite autocomplete being a pretty well defined part of the HTML5 spec, Chrome has flip-flopped on how they use the autocomplete property. Originally honoring autocomplete="off" (2013), they then decided that developers must be using it wrong and the browser should just ignore it.

This doesn't mean there aren't very valid cases where you don't want the browser autofilling data (e.g. on CRM systems), but by and large, we see those as the minority cases. And as a result, we started ignoring autocomplete=off for Chrome Autofill data.

(Source: Chromium bug from 2015 marked as WontFix)

According to the Priority of Constituencies:

In case of conflict, consider users over authors over implementors over specifiers over theoretical purity. In other words costs or difficulties to the user should be given more weight than costs to authors; which in turn should be given more weight than costs to implementors...

...Which leaves us developers in the unfortunate spot of finding a work-around. This article from MDN outlines the current state well, and offers this solution of setting autocomplete to new-password:

If an author would like to prevent the autofilling of password fields in user management pages where a user can specify a new password for someone other than themself, autocomplete="new-password" should be specified, though support for this has not been implemented in all browsers yet.

I'm not sure how long this will remain valid, but for now (tested in Chrome 53 in September 2016) this is the easiest solution:

<input type="password" name="someName" autocomplete="new-password" />

Edit: Note: This has the side-effect of asking the user to save the password, possibly overwriting an existing password. So while it does "prevent the autofilling of password fields" it does not remove the element from the autocomplete mess altogether.

Edit: Updated Info: Newer versions of Chrome once again respect the autocomplete=off attribute, as Alexander Abakumov pointed out in his answer. He had it working for Chrome 68, works on Chrome 70 for me.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
Luke
  • 18,811
  • 16
  • 99
  • 115
6

autocomplete="off" works now. Tested in the current Chrome 70.0.3538.110.

Demo.

Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
  • 1
    Thanks for pointing this out. I'm in Chrome version 70 for Mac and this solution works. – Brendan Goggin Nov 19 '18 at 20:45
  • @DavidKmenta: It works with the same Chrome version on Windows 10. Also, BrendanGoggin commented it's working on Chrome 70 for Mac. I highly doubt something changed around it. Try to test your web app on Chrome for Win and ping back a result, please. – Alexander Abakumov Nov 28 '18 at 22:12
  • 1
    @AlexanderAbakumov unfortunately I'm not the only one having this issue: https://stackoverflow.com/questions/53179114/unexpected-chrome-autofill-behaviour-disable-chrome-autofill ... it seems like there's some unknown logic behind this that only the Chrome team knows – David Kmenta Nov 29 '18 at 20:27
  • @DavidKmenta: One of the [answers](https://stackoverflow.com/a/53193537/3345644) there says: `As of recent Chrome (definitely version 70) autocomplete="off" is now respected, as long as your inputs do not look like user profile, address or credit card data.` I personally haven't experienced a situation when `autocomplete="off"` wouldn't work. If you could change my demo to demonstrate one of those situations, it would be very helpful. – Alexander Abakumov Nov 29 '18 at 21:39
  • 1
    autocomplete="nope" works well in chrome. Refer the reason here https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion#Disabling_autocompletion – kanagaraj palanisamy Jan 04 '19 at 07:44
  • @kanagarajpalanisamy The `autocomplete="nope"` approach is not a good idea. It's not cross-browser (your very link says: `this does not work in Firefox; it completely disregards the invalid value and reverts to default autocompletion behavior.`. Also, if it works in the current Chrome, it could easily be changed in the next release since this behavior goes against the standard. Why don't you use `autocomplete="off"`? – Alexander Abakumov Jan 04 '19 at 15:17
1

It looks Chrome ignores the autocomplete property for individual inputs; the old work around was to add autocomplete=off on the entire form like you have done (which is a pretty incomplete solution as it will then add this functionality to all inputs contained in the form, which may not be desired).

Anyway, from this post it looks like that work around is no longer available, so it looks like you may need a directive. I know this may not be what you're looking for, but I think it's your only option for chrome.

myApp.directive('autocomplete', function() {

    return {    

        restrict: 'A',
        link: function( $scope, el, attr ) {

            el.bind('change', function(e) {

                e.preventDefault();

            }
        }
    }

});
Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
bencripps
  • 2,025
  • 3
  • 19
  • 27