BrianTheCoder-ratpack 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/ratpack/forms.rb +5 -5
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/ratpack/forms.rb
CHANGED
@@ -2,10 +2,10 @@ module RatPack
|
|
2
2
|
module Forms
|
3
3
|
def error_messages_for(obj = nil, opts = {})
|
4
4
|
return unless obj.respond_to?(:errors)
|
5
|
+
return if obj.errors.blank?
|
5
6
|
html = tag(:h2, "Form submission failed be cause of #{obj.errors.size} #{pluralize("error",obj.errors.size)}")
|
6
|
-
obj.errors.
|
7
|
-
|
8
|
-
end
|
7
|
+
msgs = obj.errors.map{|error| error.map{|msg| tag(:li,msg)}}.flatten
|
8
|
+
tag(:div, html + tag(:ul,msgs), :class => "error")
|
9
9
|
end
|
10
10
|
|
11
11
|
%w(text password hidden file).each do |kind|
|
@@ -62,12 +62,12 @@ module RatPack
|
|
62
62
|
private
|
63
63
|
|
64
64
|
def form_field(type, content, attrs)
|
65
|
-
attrs[:id] = attrs[:name] unless attrs.has_key?(:id)
|
65
|
+
attrs[:id] = attrs[:name].gsub(/(\[)(.+?)\]$/,'_\2') unless attrs.has_key?(:id)
|
66
66
|
build_field(attrs) + tag(type, content, attrs)
|
67
67
|
end
|
68
68
|
|
69
69
|
def closed_form_field(type, attrs)
|
70
|
-
attrs[:id] = attrs[:name] unless attrs.has_key?(:id)
|
70
|
+
attrs[:id] = attrs[:name].gsub(/(\[)(.+?)\]$/,'_\2') unless attrs.has_key?(:id)
|
71
71
|
build_field(attrs) + self_closing_tag(type, attrs)
|
72
72
|
end
|
73
73
|
|