5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 02:56:22 +00:00
panel/config/initializers/bootstrap_field_with_errors.rb

14 lines
438 B
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
2020-08-03 20:13:53 +00:00
# Adaptar la renderización de campos con error de Rails para que sea
# compatible con Bootstrap4. La forma actual rompe los inputs
# personalizados.
ActionView::Base.field_error_proc = proc do |html_tag, _|
2020-08-07 14:15:06 +00:00
return unless html_tag
2020-08-03 20:13:53 +00:00
html = Nokogiri::HTML::DocumentFragment.parse html_tag
html&.children&.first&.attributes&.dig('class')&.value += ' is-invalid'
2020-08-03 20:13:53 +00:00
html&.to_s&.html_safe || html_tag
2020-08-03 20:13:53 +00:00
end