Permalink
Browse files

Show the error messages as <dt></dt><dd><p class="inline-errors">MESS…

…AGE</p></dd> under the not valid input
  • Loading branch information...
1 parent 508fb81 commit 40aca015cf8f05e7139c22cc411831fafa831172 @ptzn ptzn committed Dec 20, 2009
Showing with 16 additions and 5 deletions.
  1. +16 −4 lib/semantic_fields_renderer.rb
  2. +0 −1 lib/semantic_form_builder.rb
@@ -50,8 +50,8 @@ def check_box_tag(name, options = {})
options[:class] = append_class_name(options[:class], 'checkbox')
html << content_tag(:dd) do
checked = options.delete(:value).to_s != 'false'
- @super.check_box_tag(name, "1", checked, options) +
- @super.hidden_field_tag(name, "0")
+ @super.hidden_field_tag(name, "0") +
+ @super.check_box_tag(name, "1", checked, options)
end
end
@@ -120,15 +120,27 @@ def self.create_field_element(input_type)
define_method(field_tag_name) do |name, *args| # defines a method called 'semantic_text_field_tag'
field_helper_method = method(field_tag_name.intern)
options = field_tag_item_options(name, input_type, args[0]) # grab the options hash
+
+ errors = options[:error]
html = content_tag(:dt) do
content_tag(:label , "#{options.delete(:label)}:", :for => options[:id])
end
html << content_tag(:dd) do
html_tag = @super.send(field_tag_name, name, options.delete(:value).to_s, options)
- options.delete(:error) ? ActionView::Base.field_error_proc.call(html_tag, @object) : html_tag
+ errors ? ActionView::Base.field_error_proc.call(html_tag, @object) : html_tag
+ end
+
+ if errors
+ error_message = errors.is_a?(Array) ? errors.join(' and ') : errors
+ html << content_tag(:dt)
+ html << content_tag(:dd) do
+ content_tag(:p, error_message, :class => 'inline-errors')
+ end
end
+
+ html
end
end
@@ -172,4 +184,4 @@ def append_class_name(original_value, new_value)
(original_value || "") << " #{new_value}"
end
end
-end
+end
@@ -227,7 +227,6 @@ def simple_date_select(caption, options)
alias_method :original_select, :select
def select(attribute, choices, options = {})
label = (options.delete(:label) || attribute.to_s.humanize).gsub(' ', '&nbsp;')
- options.reverse_merge!(:error => @object.errors.on(attribute)) if @object
html = @template.content_tag("dt", @template.content_tag("label" , "#{label}:", :for => "#{object_name(:id)}_#{attribute}" ))
html << @template.content_tag("dd", original_select(attribute, choices, options))
end

0 comments on commit 40aca01

Please sign in to comment.