This question already has an answer here:
- Disabling Chrome Autofill 69 answers
How can we disable Chrome's autofill feature on certain <input>
s to prevent them from being automatically populated when the page loads?
At the same time I need to keep autocomplete enabled, so the user can still see the list of suggestions by clicking on the input or typing in it. Can this be done?
EDIT: Feel free to use plain Javascript or jQuery if you feel it is necessary or you feel like it would make your solution simpler.
My solution is based on dsuess user solution, which didn't work in IE for me, because I had to click one more time in the textbox to be able to type in. Therefore I adapted it only to Chrome:
In your css add this:
You better use disabled for your inputs, in order to prevent auto-completion.
Fix: prevent browser autofill in
Update: Mobile Safari sets cursor in the field, but does not show virtual keyboard. New Fix works like before but handles virtual keyboard:
Live Demo https://jsfiddle.net/danielsuess/n0scguv6/
// UpdateEnd
Explanation Instead of filling in whitespaces or window-on-load functions this snippet works by setting readonly-mode and changing to writable if user focuses this input field (focus contains mouse click and tabbing through fields).
No jQuery needed, pure JavaScript.
Here's the latest solution I've discovered. This stops Google filling the fields out and highlighting them yellow before you've even typed anything. Basically, if you put "display:none" on the field Google is smart enough to ignore it and move to the next field. If you put "visibility:hidden" though it counts it as a field in the form which seems to interfer with it's calculations. No javascript needed.
This might help: https://stackoverflow.com/a/4196465/683114
It looks like on load, it finds all inputs with autofill, adds their outerHTML and removes the original, while preserving value and name (easily changed to preserve ID etc)
If this preserves the autofill text, you could just set
From the original form where this was posted, it claims to preserve autocomplete. :)
Good luck!