ng-form和autocomplete ="off" [英] ng-form and autocomplete="off"

查看:115
本文介绍了ng-form和autocomplete ="off"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的角形

<ng-form name="AddTaskForm" autocomplete="off">
   ......
</ng-form>

但是,当我开始输入数据时,chrome仍然会提示我以前输入的值.

However when I begin entering data, chrome is still prompting me with previously entered values.

如何防止chrome(和所有浏览器)使用先前输入的值在输入中显示任何下拉菜单?

How can I prevent chrome (and all browsers) from showing any drop down on my input with previously entered values?

我进行了一些搜索,发现人们正在编写自定义指令,但不确定是否确实需要这样做.

I did some search and found that people were writing custom directives, but not sure if this is really required.

推荐答案

尽管autocomplete是定义明确的 HTML5规范的一部分,Chrome浏览器对它们使用autocomplete属性的方式一掷千金. 最初敬意autocomplete="off"(2013),然后他们决定开发人员一定使用错误,浏览器应该忽略它.

Despite autocomplete being a pretty well defined part of the HTML5 spec, Chrome has flip-flopped on how they use the autocomplete property. Originally honoring autocomplete="off" (2013), they then decided that developers must be using it wrong and the browser should just ignore it.

这并不意味着在非常不希望出现的情况下,您不希望浏览器自动填充数据(例如,在CRM系统上),但是总的来说,我们认为这是少数情况.因此,我们开始忽略Chrome自动填充数据的autocomplete = off.

This doesn't mean there aren't very valid cases where you don't want the browser autofilling data (e.g. on CRM systems), but by and large, we see those as the minority cases. And as a result, we started ignoring autocomplete=off for Chrome Autofill data.

(来源: 2015年以来的铬臭虫标记为WontFix )

根据选区优先级:

在发生冲突的情况下,请考虑用户胜过作者,胜过实现者,胜过说明符,而不是理论纯度.换句话说,对用户的成本或困难应比对作者的成本更重要.反过来,对实施者来说,这应该比对成本的重视更大.

In case of conflict, consider users over authors over implementors over specifiers over theoretical purity. In other words costs or difficulties to the user should be given more weight than costs to authors; which in turn should be given more weight than costs to implementors...

...不幸的是,这使我们的开发人员无法找到解决方法. MDN的这篇文章很好地概述了当前状态,并且提供了将autocomplete设置为new-password的解决方案:

...Which leaves us developers in the unfortunate spot of finding a work-around. This article from MDN outlines the current state well, and offers this solution of setting autocomplete to new-password:

如果作者希望防止用户管理页面中密码字段的自动填充,在该页面中用户可以为自己以外的其他人指定新密码,则应指定autocomplete ="new-password",尽管对此不提供支持已在所有浏览器中实现.

If an author would like to prevent the autofilling of password fields in user management pages where a user can specify a new password for someone other than themself, autocomplete="new-password" should be specified, though support for this has not been implemented in all browsers yet.

我不确定这将保持多长时间,但是目前(2016年9月在Chrome 53中进行测试),这是最简单的解决方案:

I'm not sure how long this will remain valid, but for now (tested in Chrome 53 in September 2016) this is the easiest solution:

<input type="password" name="someName" autocomplete="new-password" />

注意:这具有要求用户保存密码(可能覆盖现有密码)的副作用.因此,尽管它确实防止了密码字段的自动填充",但并没有完全从自动完成邮件中删除该元素.

Note: This has the side-effect of asking the user to save the password, possibly overwriting an existing password. So while it does "prevent the autofilling of password fields" it does not remove the element from the autocomplete mess altogether.

更新的信息:较新版本的Chrome再次尊重autocomplete=off属性,亚历山大阿巴库莫夫在回答中指出.他让它适用于Chrome 68,可以为我使用Chrome 70.

Updated Info: Newer versions of Chrome once again respect the autocomplete=off attribute, as Alexander Abakumov pointed out in his answer. He had it working for Chrome 68, works on Chrome 70 for me.

这篇关于ng-form和autocomplete ="off"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆