密码字段的自动完成关闭

问题描述:

我有一个用于编辑用户详细信息的表单.当我选择表单时,密码字段已经在其表单字段中显示了密码..所以当我只是更改其他内容然后尝试保存密码时也会进行更新..我怎样才能将密码字段留空..到目前为止,这是我尝试过的..但没有运气

I have a form for editing user details. When i select the form the password field already shows the password in its form field.. So when i just change the other things and then try to save the password also goes for updation.. How can i leave the password field blank.. This is so far what i have tried.. But no luck

<%= f.password_field :password, autocomplete: "off", class: "form-control", placeholder: "Leave as blank if you don't want to change password", value: "" %>

这是解决此问题的最佳方法.这是浏览器问题,但您必须从您的角度解决此问题.这是您使用一些 javascript 的解决方案.您应该对 passwordpassword_confirmation 执行此操作.只需添加 readonly:"readonly", onfocus:"javascript: this.removeAttribute('readonly')"

Here is the best way to fix this. It's a browser issue, but you must fix this from your view. Here is your solution with a little javascript. You should do this for both password and password_confirmation. Just add readonly:"readonly", onfocus:"javascript: this.removeAttribute('readonly')"

这是一个真实的例子:

<%= f.password_field :password, autocomplete: false, placeholder: "Leave it blank if you don't want to change your password", readonly:"readonly", onfocus:"javascript: this.removeAttribute('readonly')", class: "form-control" %>

如果需要,您将对 css 发挥创意.基本上,该字段是只读的,直到使用 js 单击(onfocus)您要删除 readonly 属性.所以这种方式更专业.

You will have be creative with your css, if you need to. Basically the field is read only until it's clicked on (onfocus) with js you're removing the readonly attribute. So this way it's much more professional.