Ruby-on-rails 在 Firefox 中关闭文本字段的自动完成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/744490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:07:41  来源:igfitidea点击:

Turning off auto-complete for text fields in Firefox

ruby-on-railsfirefox

提问by inglesp

Am supposed to be learning French at the moment, but rather than learning any vocab, I've been mucking around with a rails app that tests vocab - so it displays a word, and I have to type its translation.

我现在应该正在学习法语,但我没有学习任何词汇,而是一直在使用一个测试词汇的 rails 应用程序 - 所以它显示一个单词,我必须输入它的翻译。

Unfortunately, Firefox remembers everything I've already type there, so which diminishes its usefulness somewhat.

不幸的是,Firefox 会记住我已经在那里输入的所有内容,因此在某种程度上降低了它的实用性。

Is it possible, through the options for form_for or otherwise, to turn this normally useful behaviour off?

是否有可能通过 form_for 或其他选项来关闭这种通常有用的行为?

回答by inglesp

So it turns out it's pretty simple. Rather than

所以事实证明这很简单。而不是

<%= f.text_field :fieldname %>

put

<%= f.text_field :fieldname, :autocomplete => :off %>

回答by Jeff Steil

You can also turn off autocomplete at the form level by using the :autocomplete attribute in the :html collection, which will generate the HTML that Erv referenced. The syntax is

您还可以使用 :html 集合中的 :autocomplete 属性关闭表单级别的自动完成功能,这将生成 Erv 引用的 HTML。语法是

<% form_for :form_name, @form_name, :html => {:autocomplete => "off"} do |f|%>
...
<% end %>

回答by Erv Walter

Add autocomplete="off" as an attibute on your form tag:

在表单标签上添加 autocomplete="off" 作为属性:

<form action="..." method="..." autocomplete="off" >
</form>

回答by Jon Kern

I was using the "tag" variant of forms and found this to work:

我正在使用表单的“标签”变体并发现它可以工作:

<%= text_field_tag('favorite animal', nil, :options => {:autocomplete => 'off'}) %>

回答by Pablo Torrecilla

Below the tag variant for Rails 3applications:

Rails 3应用程序的标签变体下方:

<%= text_field_tag :search, nil, :autocomplete => 'off' %>

回答by Pablo Torrecilla

This worked for me in Rails 4+

这在 Rails 4+ 中对我有用

<%= f.text_field :name, autocomplete: :off %>

Nice and simple

好看又简单

回答by Aleksandur Atanasov

Simple solution for me in Rails 4+

Rails 中对我来说的简单解决方案 4+

In the form i added:

在我添加的表格中:

:autocomplete => "off"

And in the field:

而在现场:

:autocomplete=>"none"

Example:

例子:

  <%= form_for(@user.address_detail,
           :url => {:action => :update_address},
           :validate => true,
           :method => :put,
           :html => {:class => "form-horizontal",:autocomplete => "off"},
  ) do |f| %>

          <div class="controls">
        <%= f.text_field :address_line_1,:autocomplete=>"none" %>
      </div>