-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the form compatible with Bootstrap server side validation tools
- Loading branch information
Showing
2 changed files
with
10 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Rails form helpers wrap controls with a .field_with_errors class that prevents the validation styles from bootstrap to work. | ||
# This snippet replaces the wrapping with that class with an injection of .is-invalid class, which is bootstrap compatible. | ||
ActionView::Base.field_error_proc = proc do |html| | ||
frag = Nokogiri::HTML5::DocumentFragment.parse(html) | ||
klass = frag.children[0].attributes['class'] | ||
frag.children[0].attributes['class'].value = [klass, 'is-invalid'].join(' ') | ||
frag.to_html.html_safe # rubocop:disable Rails/OutputSafety The input is code from our views, so it's safe to disable this | ||
end |