Highlight erroneous fields by adding a class to them

The default rails scheme for highlighting errors is to wrap the
field in a div, but that changes the structure of the page and can
change the meaning of CSS rules applied to the fields.

As an alternative we now apply a class to the fields, and use that
in the CSS to apply a highlight.
This commit is contained in:
Tom Hughes 2014-01-15 21:09:54 +00:00
parent 0764bb40b2
commit 933b091330
4 changed files with 23 additions and 16 deletions

View file

@ -0,0 +1,9 @@
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
class_attr_index = html_tag.index 'class="'
if class_attr_index
html_tag.insert class_attr_index+7, 'field_with_errors '
else
html_tag.insert html_tag.index(/\/?>/), ' class="field_with_errors"'
end
end