semantic_form_for 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,17 +29,23 @@ class SemanticFormFor::FormBuilder < ActionView::Helpers::FormBuilder
|
|
29
29
|
define_method input do |attribute, *args|
|
30
30
|
options = args.extract_options!
|
31
31
|
text = args.shift
|
32
|
+
error = self.object.errors[attribute].try(:join, ', ')
|
33
|
+
|
34
|
+
classes = [ input ]
|
35
|
+
classes << 'error' if error.present?
|
32
36
|
|
33
37
|
template.capture_haml do
|
34
|
-
template.haml_tag(:li, :id => _li_id(attribute), :class =>
|
38
|
+
template.haml_tag(:li, :id => _li_id(attribute), :class => classes) do
|
35
39
|
# check boxes should have their label and input tag in the reverse
|
36
40
|
# order
|
37
41
|
if input != :check_box
|
38
42
|
template.haml_concat self.label(attribute, text)
|
43
|
+
template.haml_tag :p, error if error.present?
|
39
44
|
template.haml_concat super(attribute, options)
|
40
45
|
else
|
41
46
|
template.haml_concat super(attribute, options)
|
42
47
|
template.haml_concat self.label(attribute, text)
|
48
|
+
template.haml_tag :p, error if error.present?
|
43
49
|
end
|
44
50
|
end
|
45
51
|
end
|
@@ -56,24 +62,6 @@ class SemanticFormFor::FormBuilder < ActionView::Helpers::FormBuilder
|
|
56
62
|
end
|
57
63
|
end
|
58
64
|
|
59
|
-
def errors(message = nil, &block)
|
60
|
-
if object.errors.any?
|
61
|
-
template.capture_haml do
|
62
|
-
template.haml_tag(:div, :class => 'errors') do
|
63
|
-
template.haml_tag(:p, message) unless message.blank?
|
64
|
-
template.haml_tag(:ul) do
|
65
|
-
self.object.errors.each do |attribute, message|
|
66
|
-
template.haml_tag :li, case block_given?
|
67
|
-
when true then yield(attribute, message)
|
68
|
-
else [ attribute, message ].join(' ')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
65
|
private
|
78
66
|
|
79
67
|
def _object_name
|