Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Chrome autocomplete feature?

We want to disable autocomplete in Chrome browser in our React JavaScript application. We have tried a bunch of solutions available on the Internet but nothing worked. autoComplete=off is not reliable and so are other ways.

This is really important for us at this moment so can you please suggest us a foolproof way to disable autocomplete in Chrome using React JavaScript?

Secondly, we are using a common control/component for our text boxes and using them everywhere

like image 444
Shiva Wahi Avatar asked May 15 '18 10:05

Shiva Wahi


People also ask

How do I turn off Autocomplete input?

Use the <input> tag with autocomplete attribute. Set the autocomplete attribute to value “off”.


2 Answers

Do autocomplete="new-password" to disable autocomplete.

like image 60
illiteratewriter Avatar answered Sep 21 '22 11:09

illiteratewriter


You can override chrome autofill by add onFocus attribute.

render()
{
  return <input type="text" name="name" value="this is my input" autoComplete="off" onFocus={this.onFocus} />
}

In the onFocus method we need to change "autocomplete" attribute through javaScript.

onFocus = event => {

   if(event.target.autocomplete)
   {
     event.target.autocomplete = "whatever";
   }

};

This solution works for me.

let me know if it works for you ;)

like image 44
Dekel Dahan Avatar answered Sep 22 '22 11:09

Dekel Dahan