2

I came across this issue a few days ago. Do you anyone knew how to disable browser autocomplete on the Input element in React.js?? I already tried :

  • autoComplete="off"
  • autocomplete="new-password"

Both are not working.

Thank you for your answer.

2
  • Read more on this large thread here. Disable autocomplete on the form level, if you have one. And make sure to use autoComplete, with uppercase C. But even then, you could have suprises. Commented Jan 2, 2020 at 8:22
  • @NicolaeOlariu I don't have inputs in the form because I'm submitting this via another component. So I need to disable autoComplete on input level. Commented Jan 2, 2020 at 9:58

4 Answers 4

2

Solution from https://www.codementor.io/@leonardofaria/disabling-autofill-in-chrome-zec47xcui

What solved the issue for me is setting the form fields to read only and then removing the attribute once the user focus them.

<input readonly="readonly" onfocus="this.removeAttribute('readonly');" type="text" value="test">
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the solution. I used solution mentioned here medium.com/paul-jaworski/…
1

Yes, neither autoComplete="off" nor autocomplete="new-password" works with chrome.

Adding autocomplete attribute when input is focused works for me

onFocus={(event) => { event.target.setAttribute('autocomplete', 'off'); }}

Comments

1

The tags autoComplete="off" and autocomplete="new-password" does not work with browsers. Add this to the input tags and it will work as expected.

onFocus={(e) => e.target.setAttribute("autoComplete", "none")}

1 Comment

Thanks for saving my day. I have tried all the given solutions but only this one worked for me. This one should actually be the accepted answer.
0

On your input element delete the type attribute and all will be well. Also you don't need the autocomplete.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.