BS3 Boostrap formatted error handler which adds a span tag with “help-block with-errors” classes for the error message.
Uses [github.com/1000hz/bootstrap-validator] formatting.
Note! The default “error” class on the input is being removed.
Registered as :bs3.
Public Instance methods
call(tag, input)
Return tag with error message span tag after it.
[show source]
# File lib/forme/bs3.rb 18 def call(tag, input) 19 if tag.is_a?(Tag) 20 tag.attr[:class] = tag.attr[:class].to_s.gsub(/\s*error\s*/,'') 21 tag.attr.delete(:class) if tag.attr[:class].to_s == '' 22 end 23 attr = input.opts[:error_attr] 24 attr = attr ? attr.dup : {} 25 Forme.attr_classes(attr, 'help-block with-errors') 26 return [tag] if input.opts[:skip_error_message] 27 attr[:id] ||= input.opts[:error_id] 28 29 case input.type 30 when :submit, :reset 31 [tag] 32 when :textarea 33 input.opts[:wrapper] = :bs3 34 if input.opts[:wrapper_attr] 35 Forme.attr_classes(input.opts[:wrapper_attr], 'has-error') 36 else 37 input.opts[:wrapper_attr] = { :class => 'has-error' } 38 end 39 [ tag, input.tag(:span, attr, input.opts[:error]) ] 40 41 when :select 42 input.opts[:wrapper] = :bs3 43 if input.opts[:wrapper_attr] 44 Forme.attr_classes(input.opts[:wrapper_attr], 'has-error') 45 else 46 input.opts[:wrapper_attr] = { :class => 'has-error' } 47 end 48 [ tag, input.tag(:span, attr, input.opts[:error]) ] 49 50 when :checkbox, :radio 51 52 input.opts[:wrapper] = :div 53 if input.opts[:wrapper_attr] 54 Forme.attr_classes(input.opts[:wrapper_attr], 'has-error') 55 else 56 input.opts[:wrapper_attr] = { :class => 'has-error' } 57 end 58 59 [ 60 input.tag(:div, { :class=> input.type.to_s }, [tag] ), 61 input.tag(:span, attr, input.opts[:error]) 62 ] 63 else 64 if input.opts[:wrapper_attr] 65 Forme.attr_classes(input.opts[:wrapper_attr], 'has-error') 66 else 67 input.opts[:wrapper_attr] = { :class => 'has-error' } 68 end 69 [tag, input.tag(:span, attr, input.opts[:error])] 70 end 71 end