Skip to content

Commit

Permalink
Fix ChaelCodes#109 Added custom error HTML class from Hunters Keepers.
Browse files Browse the repository at this point in the history
Added an initializer which adds a custom error class to the HTML created
by ActionView::Base.
  • Loading branch information
exegeteio committed Oct 30, 2021
1 parent c85223e commit 36c7f8c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions config/initializers/customize_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
class_attr_index = html_tag.index 'class="'
label = html_tag.index 'label'

if label
html_tag
elsif class_attr_index
html_tag.insert class_attr_index + 7, 'is-danger '
else
"<div class=\"field_with_errors\">#{html_tag}</div>".html_safe
end
end

0 comments on commit 36c7f8c

Please sign in to comment.