加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React中autoComplete="off" 失效

发布时间:2020-12-15 20:28:34 所属栏目:百科 来源:网络整理
导读:Turning Off Autocomplete in Chrome with?React tl;dr?Add a hidden input with an arbitrary? value? attribute at the top of the form,then set semantic values for the? autocomplete? property on the input fields for which you wish to disable au

Turning Off Autocomplete in Chrome with?React

tl;dr?Add a hidden input with an arbitrary?value?attribute at the top of the form,then set semantic values for the?autocomplete?property on the input fields for which you wish to disable autocomplete.

If you’re anything like me,you’ve just spent hours attempting to get Chrome to respect your?autocomplete=”off”?property on a form input. It’s one of those bizarre and annoying front-end quirks that can drive you to the brink of insanity. You’ve Googled the issue,tried the suggestions on every blog you’ve seen,and nothing works. Hopefully I have the answer for you.

I encountered this issue on a simple login form: one email input,and one password input. I tried setting?autocomplete=”off”?on the form level,on the input level,and on both levels. I tried putting these tags above the “real” ones:

None of that worked for me.

Eventually,I found?this Chromium issue?and tried the suggestion there,which was to put some arbitrary value in the autocomplete field. Unfortunately,when React rendered the HTML,it seemed that any value I put in the?autoComplete?property,was being transformed to “off”.

Like Aaron Rodgers in the 4th quarter,I threw up a Hail Mary,and tried sticking this in at the top of my form:

Success!

I refreshed a few times,just to make sure,and to my relief,the autofill nightmare was over… until I changed the?autoComplete?values in my JSX back to “off”.

As I mentioned before,when I tried using semantic values as suggested by the Chromium developers,the HTML rendered by React seemed to ignore them,and stick in “off” no matter what input I gave it.

?

?

Well,on some level,that’s not entirely true. I don’t really understand what’s going on yet,but I know this:

If I set?autoComplete=”off”?in my JSX,Chrome will autofill the fields.

If I set semantic values for?autoComplete?AND include this tag at the top of my form…

…Chrome will not autofill the fields.

Chrome is obviously reading the?autocomplete?values passed into it,then changing them for some reason.

Ahh,the joys of front-end development.

?

文章来自:https://medium.com/paul-jaworski/turning-off-autocomplete-in-chrome-ee3ff8ef0908

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读