Sha256: 0bcd854198d5c2be366e3158ecfd8f2f1d6342f84f2eebf769e06ae6495ce4f2

Contents?: true

Size: 1014 Bytes

Versions: 27

Compression:

Stored size: 1014 Bytes

Contents

module ClassMutator
  def add_css_class(*classes)
    existing = (self["class"] || "").split(/\s+/)
    self["class"] = existing.concat(classes).uniq.join(" ")
    self
  end
end

Nokogiri::XML::Node.send(:include, ClassMutator)

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
  html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe

  form_fields = %w{textarea input select}
  elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, " + form_fields.join(", ")

  elements.each do |e|
    if e.node_name.eql? "label"
      html = e.add_css_class("error").to_s.html_safe
    elsif form_fields.include? e.node_name
      html = e.add_css_class("error").to_s.html_safe
      if instance.error_message.kind_of?(Array)
        html << "<span class=\"help-inline\">&nbsp;#{instance.error_message.join(", ")}</span>".html_safe
      else
        html << "<span class=\"help-inline\">&nbsp;#{instance.error_message}</span>".html_safe
      end
    end
  end
  html
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
houston-core-0.9.2 config/initializers/action_view_field_error_proc.rb
houston-core-0.9.1 config/initializers/action_view_field_error_proc.rb
houston-core-0.9.0 config/initializers/action_view_field_error_proc.rb
houston-core-0.9.0.rc1 config/initializers/action_view_field_error_proc.rb
houston-core-0.8.4 config/initializers/action_view_field_error_proc.rb
houston-core-0.8.3 config/initializers/action_view_field_error_proc.rb
houston-core-0.8.2 config/initializers/action_view_field_error_proc.rb
houston-core-0.8.1 config/initializers/action_view_field_error_proc.rb
houston-core-0.8.0 config/initializers/action_view_field_error_proc.rb
houston-core-0.8.0.pre2 config/initializers/action_view_field_error_proc.rb
houston-core-0.8.0.pre config/initializers/action_view_field_error_proc.rb
houston-core-0.7.0 config/initializers/action_view_field_error_proc.rb
houston-core-0.7.0.beta4 config/initializers/action_view_field_error_proc.rb
houston-core-0.7.0.beta3 config/initializers/action_view_field_error_proc.rb
houston-core-0.7.0.beta2 config/initializers/action_view_field_error_proc.rb
houston-core-0.7.0.beta config/initializers/action_view_field_error_proc.rb
houston-core-0.6.3 config/initializers/action_view_field_error_proc.rb
houston-core-0.6.2 config/initializers/action_view_field_error_proc.rb
houston-core-0.6.1 config/initializers/action_view_field_error_proc.rb
houston-core-0.6.0 config/initializers/action_view_field_error_proc.rb