Field_with_errors

If a model doesn’t pass validation the field in the view is put under
a

.
But who create that div? field_text helper do it?

Hello Mauro,

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}

”.html_safe }

Thanks!
Butu

On 5 October 2010 04:05, Butu [email protected] wrote:

@@field_error_proc = Proc.new{ |html_tag, instance| “<div
class=“field_with_errors”>#{html_tag}”.html_safe }

Thanks!
Butu

…and if I don’t want those divs?

On 5 October 2010 08:07, Mauro [email protected] wrote:

cattr_accessor :field_error_proc
@@field_error_proc = Proc.new{ |html_tag, instance| “<div
class=“field_with_errors”>#{html_tag}”.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

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

and
, 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

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

and
, for example.

.field_with_errors {
display: inline;
}

That should do the trick.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

.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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs