Disable autocomplete on Chrome / Firefox / Safari
How frustrating that the browsers forcing their internal autocomplete solution aggressively… We sometimes would need to use our unique autocomplete solutions, for example to get an element’s id based on its name.
After hours of searching, digging, trying I came up a viable hack to get rid of the autocomplete function.
The magic with the autocomplete grouping function that would help the developers to tell the browsers how to split data to separated fields. For example, if you would like to autocomplete an address but you would like to split the address to ZIP code, Country, Town, Address, you can tell to the browser what part belongs to which fields of the form.
We can use this to switch the autocomplete function off:
<input type="text" name="your_input" autocomplete="prevent-autocomplete"><!-- Add a fake hidden input with the same autocomplete group and random naming -->
<input type="text" name="{{str_random(5)}}" hidden autocomplete="prevent-autocomplete">
Just add a hidden input with the same autocomplete value, since it has random name the browsers can’t remember its older values ;)
Official documentation and more info:
