[英]Disable input auto complete on React.js
I know this has been asked a 1000 times, but all the answers say the same yet neither work for me at all.我知道这已经被问了 1000 次,但所有的答案都说相同,但对我来说根本不起作用。
Here'm my input field:这是我的输入字段:
<input
className={
required ? "input-field__input input-field__input--required" : "input-field__input"
}
id={placeHolder}
type={type}
placeholder={placeHolder}
autoComplete="new-password"
value={value || ""}
onChange={e => handleChange(e.target.value)}
/>
I've tried autoComplete="new-password"
, autocomplete="new-password"
, autoComplete="none"
& autocomplete="none"
but chrome keeps showing me sugestions based on past inputs, no matter which one I've tried.我试过
autoComplete="new-password"
, autocomplete="new-password"
, autoComplete="none"
& autocomplete="none"
但无论我试过哪一个,chrome 都会根据过去的输入向我显示建议. Is there something else happening that might affect it?还有其他事情可能会影响它吗?
Add autoComplete="off" in the form tag instead of the input tag.在表单标签而不是输入标签中添加 autoComplete="off"。 Below is the code to follow :-
以下是要遵循的代码:-
<form autoComplete="off">
<input id="input" type="text" placeholder="Enter Text" />
</form>
{autoComplete} syntax ie camelCase for React, html follow {autocomplete} in lowercase. {autoComplete} 语法,即 React 的驼峰式,html 后跟 {autocomplete} 小写。 JSX also convert it to lower case.
JSX 也将其转换为小写。 You can see the rendered DOM.
您可以看到渲染的 DOM。
Here is the demo :- https://codepen.io/gahlotbaba/pen/JjdzmmB?editors=0111这是演示:- https://codepen.io/gahlotbaba/pen/JjdzmmB?editors=0111
Hope it helps.希望能帮助到你。
you can add a dummy invisible input above your password您可以在密码上方添加一个虚拟的隐形输入
<div style={{ height: 0px; overflow: hidden; background: transparent; }}>
<input type="password"></input>
</div>
autoComplete="new-password"
should work for you. autoComplete="new-password"
应该适合你。
this will remove the autocomplete这将删除自动完成
more on this here更多关于这里
https://github.com/react-toolbox/react-toolbox/issues/1795 https://github.com/react-toolbox/react-toolbox/issues/1795
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.