Skip to content

Commit

Permalink
Show the error messages as <dt></dt><dd><p class="inline-errors">MESS…
Browse files Browse the repository at this point in the history
…AGE</p></dd> under the not valid input
  • Loading branch information
ptzn committed Dec 20, 2009
1 parent 508fb81 commit 40aca01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
20 changes: 16 additions & 4 deletions lib/semantic_fields_renderer.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -172,4 +184,4 @@ def append_class_name(original_value, new_value)
(original_value || "") << " #{new_value}"
end
end
end
end
1 change: 0 additions & 1 deletion lib/semantic_form_builder.rb
Expand Up @@ -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
Expand Down

0 comments on commit 40aca01

Please sign in to comment.