Files

Class Index [+]

Quicksearch

Ubiquo::Extensions::ActionView

Public Class Methods

ubiquo_field_error_proc() click to toggle source

Return a proc that marks an html tag as an error

    # File vendor/plugins/ubiquo_core/lib/ubiquo/extensions/action_view.rb, line 5
 5:       def self.ubiquo_field_error_proc
 6:         Proc.new do |html_tag, instance|
 7:           msg = instance.error_message
 8:           error_class = Ubiquo::Config.get(:error_field_class)
 9:           unless (html_tag =~ /<input.*?type=\"(checkbox|radio|file)\"/)
10:             if html_tag =~ /<(input|textarea|select)[^>]+class=/
11:               class_attribute = html_tag =~ /class=['"]/
12:               html_tag.insert(class_attribute + 7, "#{error_class} ")
13:             elsif html_tag =~ /<(input|textarea|select)/
14:               first_whitespace = html_tag =~ /\s/
15:               html_tag[first_whitespace] = " class='#{error_class}' "
16:             end
17:             html_tag
18:           else
19:             # There are 3 special type input (checkbox, radio, file) for which
20:             # setting the class on the element won't work. In this case, create
21:             # a surrounding span.
22:             case html_tag
23:               when /type=\"file\"/
24:                 "<div class=\"file_#{error_class}\">" + html_tag + "</div>"
25:               when /type=\"checkbox\"/
26:                 "<span class=\"checkbox_#{error_class}\">" + html_tag + "</span>"
27:               when /type=\"radio\"/
28:                 "<span class=\"radio_#{error_class}\">" + html_tag + "</span>"
29:               else
30:                 "<span class=\"#{error_class}\">" + html_tag + "</span>"
31:             end
32:           end
33:         end
34:       end

Disabled; run with $DEBUG to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.