【问题标题】:rails 4 simple_form turn off autocomplete at form levelrails 4 simple_form 在表单级别关闭自动完成
【发布时间】:2013-07-17 15:43:33
【问题描述】:

我在我的应用程序中设置了自动完成功能,在测试过程中我注意到它突然失败了,而它刚刚在不久之前工作。应用程序返回一个pg 错误,声称employee_id 值为空

我意识到浏览器本机自动完成提示我输入了该值,因此 js 没有将 id 值插入隐藏字段。

在查看 Mozilla 文档时,我发现他们建议在表单级别关闭自动完成功能。我正在使用 simple_form,但不知道该怎么做。

<form name="form1" id="form1" method="post" autocomplete="off"

【问题讨论】:

    标签: ruby-on-rails simple-form


    【解决方案1】:

    只需将autocomplete 选项传递给:html 哈希:

    <%= simple_form_for @user, html: { autocomplete: 'off' } do |f| %>
      <%= f.input :country, as: :string %>
    <% end %>
    

    【讨论】:

    • 没有太用力挖掘,我传递的是错误的东西......“关闭”效果很好。谢谢瓦西里
    • 这个已经不行了,你需要下面的答案?
    • 在 Rails 5.1 上为我工作,simple_form 4.0.1
    【解决方案2】:

    如果您只想为一个或多个属性而不是整个表单关闭它,您可以使用选项“input_html”,如下所示:

    <%= simple_form_for(@user, url: @form_url) do |f| %>
        ...
        <%= f.input :password, input_html: { autocomplete: 'off' } %>
        <%= f.submit %>
    <% end %>
    

    【讨论】:

      猜你喜欢
      • 2017-02-07
      • 1970-01-01
      • 2020-06-16
      • 2011-10-23
      • 2018-06-28
      • 2021-04-14
      • 1970-01-01
      • 1970-01-01
      • 2016-02-14
      相关资源
      最近更新 更多