ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| | |
html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe | |
# add nokogiri gem to Gemfile | |
elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input" | |
elements.each do |e| | |
if e.node_name.eql? 'label' | |
html = %(<div class="clearfix error">#{e}</div>).html_safe | |
elsif e.node_name.eql? 'input' | |
if instance.error_message.kind_of?(Array) | |
html = %(<div class="clearfix error">#{html_tag}<span class="help-inline"> #{instance.error_message.join(',')}</span></div>).html_safe | |
else | |
html = %(<div class="clearfix error">#{html_tag}<span class="help-inline"> #{instance.error_message}</span></div>).html_safe | |
end | |
end | |
end | |
html | |
end |
// Place all the styles related to the YourController controller here. | |
// They will automatically be included in application.css. | |
// You can use Sass (SCSS) here: http://sass-lang.com/ | |
form .clearfix:before, form .clearfix:after { | |
display: inline; | |
} |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
igmarin
commented
Jan 6, 2012
Wow, great, it works excellent, thank you very much Trent! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
Glad it helped! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
bogdanconstantinescu
May 9, 2012
I forked your version to https://gist.github.com/2645498 and it now does also textarea validation with latest Bootstrap.
bogdanconstantinescu
commented
May 9, 2012
I forked your version to https://gist.github.com/2645498 and it now does also textarea validation with latest Bootstrap. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
tomwang1013
Jun 27, 2012
The error message is below the error field, i.e. in a second line. How to place it in the same line as the error field?
tomwang1013
commented
Jun 27, 2012
The error message is below the error field, i.e. in a second line. How to place it in the same line as the error field? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
jdjkelly
commented
Nov 1, 2012
This is great, thanks. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
dustMason
Jun 19, 2013
Forked to https://gist.github.com/dustMason/5817510 for Zurb Foundation 4. This version removes the Nokogiri dependency and thus performs better.
dustMason
commented
Jun 19, 2013
Forked to https://gist.github.com/dustMason/5817510 for Zurb Foundation 4. This version removes the Nokogiri dependency and thus performs better. |
Wow, great, it works excellent, thank you very much Trent!