使用rails form_tag关闭自动完成功能

时间:2023-01-23 20:34:00

I'm trying to turn autocomplete off in one of my rails forms. Here's what I've tried so far:

我试图在我的一个rails表单中关闭自动完成功能。这是我到目前为止所尝试的内容:

# add it at the form level
= form_tag admin_sessions_path, autocomplete: "off" do

That didn't work.

那没用。

# add it at the element level
.panel
  = label_tag :email
  = email_field_tag :email, params[:email], autocomplete: 'off'

Neither did that.

也没有那样做。

# add it to both
= form_tag admin_sessions_path, autocomplete: "off" do

  # add it at the element level
  .panel
    = label_tag :email
    = email_field_tag :email, params[:email], autocomplete: 'off'

When I visit my form, my email address and saved password are already filled-in. What am I doing wrong here? I love rails, but it really drives me mad sometimes.

当我访问我的表单时,我的电子邮件地址和已保存的密码已经填写完毕。我在这做错了什么?我喜欢铁轨,但它有时让我很生气。

3 个解决方案

#1


9  

As of Rails 4+

从Rails 4+开始

Disable autocomplete for an entire form with form_tag:

使用form_tag禁用整个表单的自动填充功能:

= form_tag admin_sessions_path, html: { autocomplete: "off" } do

Disable autocomplete for an entire form with form_for:

使用form_for禁用整个表单的自动填充:

= form_for @user, html: { autocomplete: "off" } do |f|

Disable autocomplete for a single form element:

禁用单个表单元素的自动完成:

= f.text_field :foo, autocomplete: 'off'

Hope this helps!

希望这可以帮助!

#2


2  

the autocomplete attribute should be assigned to the html key like so:

应将autocomplete属性分配给html键,如下所示:

html: {autocomplete: 'off'}

#3


1  

There several ways of turning off the autocomplete functionality:

有几种方法可以关闭自动完成功能:

On form level: (autoceomplete turned of for all inputs)

在表单级别:(所有输入的autoceomplete转为)

<% form_tag(:form_name, @form_name, autocomplete = "off") do |f|%>

Per input:

<%= text_field_tag('my input', nil, autocomplete = 'off') %>

Simple Form per input:

每个输入的简单表格:

<% f.text_field :fieldname, input_html: {autocomplete: 'off'} %>

#1


9  

As of Rails 4+

从Rails 4+开始

Disable autocomplete for an entire form with form_tag:

使用form_tag禁用整个表单的自动填充功能:

= form_tag admin_sessions_path, html: { autocomplete: "off" } do

Disable autocomplete for an entire form with form_for:

使用form_for禁用整个表单的自动填充:

= form_for @user, html: { autocomplete: "off" } do |f|

Disable autocomplete for a single form element:

禁用单个表单元素的自动完成:

= f.text_field :foo, autocomplete: 'off'

Hope this helps!

希望这可以帮助!

#2


2  

the autocomplete attribute should be assigned to the html key like so:

应将autocomplete属性分配给html键,如下所示:

html: {autocomplete: 'off'}

#3


1  

There several ways of turning off the autocomplete functionality:

有几种方法可以关闭自动完成功能:

On form level: (autoceomplete turned of for all inputs)

在表单级别:(所有输入的autoceomplete转为)

<% form_tag(:form_name, @form_name, autocomplete = "off") do |f|%>

Per input:

<%= text_field_tag('my input', nil, autocomplete = 'off') %>

Simple Form per input:

每个输入的简单表格:

<% f.text_field :fieldname, input_html: {autocomplete: 'off'} %>