Autofill populating wrong fields
Asked Answered
M

14

53

I have a site with a checkout page that has always worked beautifully.
Recently, any customer that uses autofill to fill out his info, gets his email address dumped into the company field. There are no changes that we did that could affect that. What other tools can I use to get to the bottom of this?

Massacre answered 23/12, 2015 at 20:58 Comment(6)
Something must have changed to make the browser think that your company field might be a email address... might be some helpful information here: #7223668Jacky
@Jacky nothing changed on our site's code, that's why I'm trying to figure out if a recent release of Chrome for example changed the way it relates to autofillMassacre
@Jacky there were changes, but I rolled them all back and that didn't change anything.Massacre
i still don't know what caused the issue, but for anyone seeing this we ended up hiding the field so that auto-fill doesn't fill it - on focus, it becomes active and the user can manually fill it inMassacre
Is your company field right above a password field? I have more or less the same issue, and I suspect Chrome to consider that the field just above a password field is the username/email field.Bays
As of 1/2020, Chrome 79 appears to search at least both label and name attributes to determine if it will autofill something them.Oceanus
M
21

We still don't know what caused the issue, but for anyone seeing this we ended up making the field readonly so that auto-fill doesn't fill it. We then wrote some JS that on focus, it becomes active and the user can manually fill it in.

<input type="text" name="company" readonly="" onfocus="this.removeAttribute('readonly');">

Massacre answered 23/8, 2017 at 15:11 Comment(3)
When readonly field is clicked, autofill options are displayed. It is not correct solution, at least for me.Folly
I also had this problem on React-native android. Has anyone solved this problem yet?Cornwell
note: we tried solving the issue this way and the readonly/removeAttribute was flagged by our security team because of calling a function on the password field... (.removeAttribute())Rance
K
31

The OP's problem may have been solved (or may have come back again in recent updates!) but as of early 2019, you can diagnose some of these problems by setting the show-autofill-type-predictions flag in chrome://flags, restarting Chrome, then looking at the title (tooltip text) for the input in question. It will tell you what information is being used to guess the "type" of field, and what kind of saved data should be used to populate it.

Katz answered 18/2, 2019 at 11:48 Comment(1)
This is still relevant in mid 2022Frigg
M
21

We still don't know what caused the issue, but for anyone seeing this we ended up making the field readonly so that auto-fill doesn't fill it. We then wrote some JS that on focus, it becomes active and the user can manually fill it in.

<input type="text" name="company" readonly="" onfocus="this.removeAttribute('readonly');">

Massacre answered 23/8, 2017 at 15:11 Comment(3)
When readonly field is clicked, autofill options are displayed. It is not correct solution, at least for me.Folly
I also had this problem on React-native android. Has anyone solved this problem yet?Cornwell
note: we tried solving the issue this way and the readonly/removeAttribute was flagged by our security team because of calling a function on the password field... (.removeAttribute())Rance
E
14

Found myself in a similar problem, and the autocomplete property is what to be used in this situations

<input type="text" name="fooBar" autocomplete="organization" > 

exhaustive list of autocomplete/autofill tags for html form inputs

Envoy answered 17/11, 2017 at 10:46 Comment(4)
Lol I have an input element with the name and id attributes both as "company" but somehow some customers are getting that auto-filled with their birth year. Took us a while to realize what was happeningKrissykrista
I found this link to be much more helpful actually: developers.google.com/web/updates/2015/06/…Harker
This is the correct answer. This also demonstrates how to use the autocomplete attribute.Pulvinus
comprehensive details and a full list of updated attribute values for` autocomplete` from MDN developer.mozilla.org/en-US/docs/Web/HTML/Attributes/…Mev
S
6

I encountered a similar problem, having a "company" field placed under a "name" field. That company field was auto-filled with a birth year. It came from another form on the same site that was displaying a "birthdate" field group just below the "name" field. So chrome stored its auto-fill values in that order. I ended up with changing my second form field order (sadly it was the best I could do).

Soldo answered 12/4, 2017 at 8:44 Comment(1)
I had a similar experience. It seems Chrome will sometimes expect form fields to be in a specific order. The workaround is to define an autocomplete attribute to force Chrome to autofill correctly, as per @catalint. See html.spec.whatwg.org/multipage/…Pulvinus
S
4

You need to add name to the input tag. Browsers use name to identify what info is supposed to go into the field. You can also use the same for ID and for placeholder if you like. Try this:

<input type="text" name="company" id="company" placeholder="company">

If that still does not work, you might consider turning off autofill for that particular field*:

<input type="text" name="company" id="company" placeholder="company" autocomplete="off">

*you can also turn off autofill for the whole form using the same autocomplete property and off value.

Superbomb answered 5/9, 2017 at 20:37 Comment(1)
autocomplete="off" won't work in the modern browsers since now they override this behavior. try setting some misc text with autocomplete attribute like autocomplete="nahnah"Mev
A
3

We recently started having an issue like this with our shopping cart page when it was viewed from chrome and you had a saved user name and password for the site. Chrome would inexplicably put the user name value into the quantity box. After much hair-pulling, we realized that there were a hidden user name and password field on the page. These auto-filled correctly when visible. When hidden chrome would auto-fill the quantity input box. By setting autocomplete="username" and autocomplete="current-password" on these controls the issue went away.

Affliction answered 7/8, 2019 at 22:19 Comment(1)
Unfortunately not ideal, but the only solution here that worked for me in MS Edge 88. Thanks!Brinson
S
2

The Almost Invisible Input Proxy Trick

I just encountered the same issue with the Chrome 72... It just wanted to fill any kind of field (select or input) as long it was not readonly (with complete no respect for name, autocomplete, etc attributes), with any kind of value it may have stored previously.

  • You may want to avoid the field to be populated because you listen on the change event or there are some validation on input that may trigger error message just because of bad autofill.
  • You just want the autofill value to be discarded and not even show (even before javascript execution).

You just provide another field for the browser to fill and you make it almost impossible to see by hiding it under the other field.

    <input type="text" id="autofill-if-you-dare" style="position: absolute; z-index: -1; top: 20px; width: 0; height:0" />

Note: You can still hide or remove it by javascript afterwards but you should not hide it before autofilling has been completed, because Chrome will populate only visible fields. And as other answers have stated, it doesn't trigger any event, so you must rely on polling to do so.

Spalato answered 15/2, 2019 at 12:9 Comment(1)
Thanks its hacky solution but worked for me till chrome gets fixed it self, users were really getting irritated with this issue, in angular application I have to add this line at the bottom of master[top level] component.Hodgkin
G
2

I solved this problem by making sure the section I was adding was actually wrapped in a <form> tag. The site's global "search" field was being considered part of the page's form because neither had a <form> tag.

Since you can have inputs outside of forms, and this isn't really a big problem for a single-page-app (maybe not the best practice though!), this might be a worthwhile thing to check.

Graver answered 19/11, 2020 at 19:9 Comment(1)
Exact same thing happened to me. Great insight that if this is happening to cut off one form from anotherKuenlun
B
1

I had the problem that chrome will fill in my email in all fields in one of my forms. The other form works correctly. I found the problem is that the word Name must be before the name input. Or the word email must be before input for email. I had it afterwards. Also using <label for="email">Your email</label> after the email input worked.

**Incorrect autocomplete:**
<input type="text" name="name"/> Your name
<input type="email" name="email"/> Your email

**Correct autocomplete:**
Your name <input type="text" name="name"/>
Your email <input type="email" name="email"/>
or
<label for="name">Your name</label> <input type="text" name="name"/>
<label for="email">Your email</label> <input type="email" name="email"/>
or
<input type="text" name="name"/> <label for="name">Your name</label>
<input type="email" name="email"/> <label for="email">Your email</label>
Brandybrandyn answered 16/7, 2020 at 21:41 Comment(0)
B
1

February 2021:
autocomplete="__away" worked for me src.
autocomplete="new-password" also worked src.

Still hacky but it worked for me in Chrome and MS Edge both 88.0.7.

Related(Duplicate?) questions:
Autocomplete Off is completely Ignored
Disabling Chrome Autofill
Autocomplete off vs false?

Brinson answered 12/2, 2021 at 8:11 Comment(0)
F
1

In Chrome, add this on the top of the page:

<input id="" class="" name="" type="password" style="display: none;">
Faroff answered 21/3, 2022 at 11:43 Comment(0)
T
0

I have been encountering this issue lately, specifically with chrome. It seems that

autocomplete="off"

isnt being picked up anymore by Chrome. I found the following sources helpful :

Chromium (which i believe is what a lot of Chrome is based on) has the following code that shows the regex that is used when finding fields to populate with Chrome's autocomplete:

https://cs.chromium.org/chromium/src/components/autofill/core/common/autofill_regex_constants.cc?sq=package:chromium&g=0&l=262

I feel like they only other work around that I have found is to follow these conventions : https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete

Or at least make sure that you give an attribute that's disimilar enough from the above list so it that wont get picked up by autocomplete features.

Telluric answered 18/1, 2019 at 9:41 Comment(0)
T
0

Suppose there are three fields, One with wrong autocomplete.

<input type="text" name="field1"/> 
<input type="password" name="field2"/> 
<input type="text" name="wrongAutocompleteField3"/> 

Now make display of wrongAutocompleteField3 as none:

<style>
.d-none{
   display:none;
}
</style>
....
<input type="text" name="wrongAutocompleteField3" class="d-none"/> 

On page load remove this .d-none class:

<script>
$(function(){
   $('[name="wrongAutocompleteField3"]').removeClass('d-none');
});
</script>
Tortuosity answered 25/9, 2020 at 6:5 Comment(1)
why is this helpful?Pulvinus
N
0

You need to add form tag

<form action="#" method="GET">
    <input type="text" name="text"/>
</form>
Nottingham answered 10/5, 2022 at 3:7 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Hereabouts

© 2022 - 2024 — McMap. All rights reserved.