extend form builder with error messages
This commit is contained in:
@@ -25,7 +25,7 @@
|
|||||||
+grid-column($columns: 9, $last-column:true)
|
+grid-column($columns: 9, $last-column:true)
|
||||||
&.half
|
&.half
|
||||||
+grid-column(6)
|
+grid-column(6)
|
||||||
.error
|
.error, .error-message
|
||||||
color: $alert-color
|
color: $alert-color
|
||||||
&.form-actions
|
&.form-actions
|
||||||
padding-top: 12px
|
padding-top: 12px
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class CustomFormBuilder < ActionView::Helpers::FormBuilder
|
|||||||
)
|
)
|
||||||
t.content_tag(:div, elements.inject(&:+), class: 'form-actions')
|
t.content_tag(:div, elements.inject(&:+), class: 'form-actions')
|
||||||
end
|
end
|
||||||
|
|
||||||
def row(attribute, options={}, &block)
|
def row(attribute, options={}, &block)
|
||||||
t = @template
|
t = @template
|
||||||
classes = []
|
classes = []
|
||||||
@@ -19,5 +20,15 @@ class CustomFormBuilder < ActionView::Helpers::FormBuilder
|
|||||||
classes << 'error' if object.errors[attribute].present?
|
classes << 'error' if object.errors[attribute].present?
|
||||||
t.content_tag(:div, t.capture(&block), class: classes)
|
t.content_tag(:div, t.capture(&block), class: classes)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def error_message(attribute, options={}, &block)
|
||||||
|
if errors = object.errors[attribute].presence
|
||||||
|
t = @template
|
||||||
|
classes = ['error-message']
|
||||||
|
classes << attribute
|
||||||
|
classes |= Array.wrap(options[:class])
|
||||||
|
t.content_tag(:span, options[:message] || errors.join(', '), class: classes)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
ActionView::Base.default_form_builder = CustomFormBuilder
|
ActionView::Base.default_form_builder = CustomFormBuilder
|
||||||
|
|||||||
Reference in New Issue
Block a user