Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable autocomplete for Chrome 66

With chrome 66 I couldn't find a way to disable autocomplete on text inputs like it used to work. I tried autocomplete="off" and autocomplete="new-password" which worked until Chrome 63 I think but doesn't anymore.

Is there a new way to disable this feature ?

Thanks !

like image 218
jojo____ Avatar asked Apr 27 '18 08:04

jojo____


2 Answers

Just ran into this -- Google looks at the fields id or name to determine if it has saved data for that field. As a site author, use a randomly generated name/id, and/or add an autocomplete=<random string> to the field.

See this playground: https://jsfiddle.net/mfdc22pz/1/

BTW Chrome Canary (68) fixes this bug!

In Short: Add random tags like: name="foo_90553-4"

like image 115
Moos Avatar answered Dec 18 '22 17:12

Moos


I resolved using a little jQuery (but you can use a simple javascript).

The problem is that chrome looks at the name and/or the id of your fields. The only solution I found is to remove those attributes, add an data-name attribute with the real name of the field, and re-attach the name attribute after the submit using javascript.

There is an example

<form onsubmit="return formSubmit(this);" autocomplete="off">
    <input type="text" data-name="dateStart" class="form-control" />
</form>


<script>
function formSubmit(form) {
  console.log(form);
  $(form).find('.form-control').each(function(){
    $(this).attr('name', $(this).data('name'));
  });
  console.log(form);
  query = jQuery(form).serialize();
  window.open("/YOUR_URL/?" + query, "_self");
  return false;
};
</script>
like image 42
Dario Latini Avatar answered Dec 18 '22 18:12

Dario Latini