some error reporting for forms
Oleg
committed Oct 06, 2010
commit c8bec8feb9ba7f96a6e732f745a29a6abaa3eb5a
Showing 3
changed files with
30 additions
and 5 deletions
app/views/cms_admin/pages/_form.html.erb
+2
-1
| @@ | @@ -1,8 +1,9 @@ |
| + | <%= form.error_message %> |
| <%= form.text_field :label, :id => 'slugify' %> | |
| <div class='page_form_extras'> | |
| <%= form.text_field :slug, :id => 'slug' %> | |
| - | <%= form.select :cms_layout_id, CmsLayout.options_for_select, {}, 'data-page-id' => @cms_page.id.to_i %> |
| + | <%= form.select :cms_layout_id, CmsLayout.options_for_select, {}, 'data-page-id' => @cms_page.id.to_i, :label => 'Layout' %> |
| </div> | |
| <%= render :partial => 'form_blocks' %> | |
comfortable_mexican_sofa/cms_form_builder.rb b/lib/comfortable_mexican_sofa/cms_form_builder.rb
+9
-1
| @@ | @@ -19,7 +19,9 @@ class CmsFormBuilder < ActionView::Helpers::FormBuilder |
| %( | |
| <div class='form_element #{type}_element'> | |
| <div class='label'>#{label_for(field, options)}</div> | |
| - | <div class='value'>#{yield}</div> |
| + | <div class='value'> |
| + | #{yield} |
| + | </div> |
| </div> | |
| ).html_safe | |
| end | |
| @@ | @@ -29,6 +31,12 @@ class CmsFormBuilder < ActionView::Helpers::FormBuilder |
| "<label for=\"#{object_name}_#{field}\">#{label}</label>".html_safe | |
| end | |
| + | def error_message(message = nil) |
| + | return if @object.errors.blank? |
| + | message ||= 'Failed to save. Please correct marked fields.' |
| + | "<div class='form_error'>#{message}</div>".html_safe |
| + | end |
| + | |
| def submit(value, options = {}, &block) | |
| extra_content = @template.capture(&block) if block_given? | |
| cancel_link ||= options[:cancel_url] ? ' or ' + options.delete(:cancel_url) : '' | |
public/stylesheets/comfortable_mexican_sofa/structure.css
+19
-3
| @@ | @@ -92,7 +92,13 @@ html, body { |
| .form_element .value input, | |
| .form_element .value textarea, | |
| .form_element .value select { | |
| - | width: 99%; |
| + | width: 98%; |
| + | } |
| + | .form_element .value input, |
| + | .form_element .value textarea { |
| + | border: 1px solid #ccc; |
| + | padding: 2px; |
| + | font-family: 'Courier New', Courier, monospace; |
| } | |
| .form_element .value textarea { | |
| height: 300px; | |
| @@ | @@ -103,7 +109,6 @@ html, body { |
| .page_form_extras { | |
| margin-bottom: 25px; | |
| } | |
| - | |
| .form_element.cms_tag_field_datetime .label, | |
| .form_element.cms_tag_field_integer .label, | |
| .form_element.cms_tag_field_string .label, | |
| @@ | @@ -116,4 +121,15 @@ html, body { |
| .form_element.cms_tag_page_text .label { | |
| border-color: #3F7300; | |
| } | |
| - | |
| \ No newline at end of file | |
| + | .form_error { |
| + | background-color: #9e0b0f; |
| + | font-size: 14px; |
| + | color: #fff; |
| + | padding: 5px; |
| + | text-align: center; |
| + | margin-bottom: 10px; |
| + | } |
| + | .form_element .value .field_with_errors input, |
| + | .form_element .value .field_with_errors textarea { |
| + | border-color: #9e0b0f; |
| + | } |
| \ No newline at end of file | |