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
Use the <input> tag with autocomplete attribute. Set the autocomplete attribute to value “off”.
Do autocomplete="new-password"
to disable autocomplete.
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 ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With