Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails simple_form: How to disable error labels?

I'm trying to stop simple_form from adding error labels entirely.

tried the followign CSS:

label.error { display:none; }

but simple_form's JavaScript is setting the following rule when it's generated:

display: block;

Am I missing a config that lets me turn off generation entirely?

This stops them from appearing, which works for now:

label.error {
  display: none !important;
  visibility:hidden;
}
like image 453
pbonnell Avatar asked Jun 23 '11 17:06

pbonnell


3 Answers

Give this a try:

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

Source @ lib/simple_form/components/errors.rb

If you want to disable for ALL fields, I believe you'd have to put this on all fields.

like image 183
Mike Vormwald Avatar answered Oct 21 '22 11:10

Mike Vormwald


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

like image 28
Addicted Avatar answered Oct 21 '22 11:10

Addicted


If you want to disable error messages on inputs site-wide, you can set this easily in the initialiser 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

You will no longer see the validation messages beside every input.

like image 23
sergserg Avatar answered Oct 21 '22 10:10

sergserg