field_with_errors.

If a model doesn't pass validation the field in the view is put under
a <div class="field_with_errors">.
But who create that div? field_text helper do it?

Hello Mauro,

<div class="field_with_errors"> tag is created in ActionView::Base
class only in case of any errors.

From Rails code base:-

    # Specify the proc used to decorate input tags that refer to
attributes with errors.
    cattr_accessor :field_error_proc
    @@field_error_proc = Proc.new{ |html_tag, instance| "<div
class=\"field_with_errors\">#{html_tag}</div>".html_safe }

Thanks!
Butu

....and if I don't want those divs?

For my education, why would you object to them being there?

Colin

Hi,

If you have your own way of handling errors in your views, you can
disable rails default encapsulation by doing

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
   html_tag
end

inside an initializer.

and so no "field_with_errors" div will be wrapped around your fields.

> ....and if I don't want those divs?

For my education, why would you object to them being there?

Something that has bothered me from time to time is that when there
are errors the <div> tag takes the whole line and makes the field to
end up in the next line, instead of appearing next to its label.
Another thing that annoys me is that if I create labels using the form
object (f.label ...) the label is also marked as in error, for that
reason only I don't use the form object to create labels.

I have never had the time to look for a solution but there might be an
easy one. It would be nice if one could choose between <div> and
<span>, for example.

pepe wrote:

> ....and if I don't want those divs?

For my education, why would you object to them being there?

Something that has bothered me from time to time is that when there
are errors the <div> tag takes the whole line and makes the field to
end up in the next line, instead of appearing next to its label.
Another thing that annoys me is that if I create labels using the form
object (f.label ...) the label is also marked as in error, for that
reason only I don't use the form object to create labels.

I have never had the time to look for a solution but there might be an
easy one. It would be nice if one could choose between <div> and
<span>, for example.

.field_with_errors {
  display: inline;
}

That should do the trick.

Best,

.field_with_errors {
display: inline;

}

That should do the trick.

Thanks Marnen. I'll try that.

.field_with_errors {
display: inline;

}

Just tried it and worked as expected. Thanks Marnen.