11

我试图simple_form完全停止添加错误标签。

尝试了以下CSS:

label.error { display:none; }

但是simple_form的 JavaScript 在生成时设置了以下规则:

display: block;

我是否缺少让我完全关闭生成的配置?

这会阻止它们出现,目前有效:

label.error {
  display: none !important;
  visibility:hidden;
}
4

4 回答 4

35

试试这个:

<%= f.input :password, error: false %> 

来源@lib/simple_form/components/errors.rb

如果你想禁用所有字段,我相信你必须把它放在所有字段上。

于 2011-07-09T03:49:37.193 回答
3

You can also disable labels, hints or error or configure the html of any of them:

  <%= simple_form_for @user do |f| %>
    <%= f.input :username, :label_html => { :class => 'my_class' } %>
    <%= f.input :password, :hint => false, :error_html => { :id => "password_error"} %>
    <%= f.input :password_confirmation, :label => false %>
    <%= f.button :submit %>
  <% end %>

For further reference check the link below:

https://github.com/plataformatec/simple_form

于 2011-06-23T18:17:01.003 回答
2

如果您想禁用站点范围内的输入错误消息,您可以在初始化程序中轻松设置config/initializers/simple_form.rb

SimpleForm.setup do |config|
  config.wrappers :default, class: :input,
    # Comment this line!
    #b.use :error, wrap_with: { tag: :span, class: :error }
  end
end

您将不再在每个输入旁边看到验证消息。

于 2014-04-25T15:06:42.203 回答
0

在 Rails 5 中,执行以下操作以从上方删除输入字段下方的提示和标签

<%= f.input :password, required: true, label: false, hint: false %>
于 2017-06-20T11:58:45.483 回答