Skip to content

Commit

Permalink
Ensure labels do the proper I18n lookup, resolving issue #31
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Aug 6, 2009
1 parent 6ef7054 commit d98197e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions lib/formtastic.rb
Expand Up @@ -330,6 +330,8 @@ def semantic_fields_for(record_or_name_or_array, *args, &block)
# * :label - An alternative form to give the label content. Whenever label
# is false, a blank string is returned.
# * :as_span - When true returns a span tag with class label instead of a label element
# * :input_name - Gives the input to match for. This is needed when you want to
# to call f.label :authors but it should match :author_ids.
#
# == Examples
#
Expand All @@ -343,23 +345,23 @@ def semantic_fields_for(record_or_name_or_array, *args, &block)
def label(method, options_or_text=nil, options=nil)
if options_or_text.is_a?(Hash)
return if options_or_text[:label] == false

options = options_or_text
text = options.delete(:label)
text = options.delete(:label)
else
text = options_or_text
text = options_or_text
options ||= {}
end

text = localized_attribute_string(method, text, :label)
text ||= humanized_attribute_name(method)
text << required_or_optional_string(options.delete(:required))
text << required_or_optional_string(options.delete(:required))

input_name = options.delete(:input_name) || method
if options.delete(:as_span)
options[:class] ||= 'label'
template.content_tag(:span, text, options)
else
super(method, text, options)
super(input_name, text, options)
end
end

Expand Down Expand Up @@ -578,7 +580,7 @@ def select_input(method, options)
end

input_name = generate_association_input_name(method)
self.label(input_name, options.slice(:label, :required)) +
self.label(method, options.slice(:label, :required).merge(:input_name => input_name)) +
self.select(input_name, collection, set_options(options), html_options)
end
alias :boolean_select_input :select_input
Expand Down
4 changes: 2 additions & 2 deletions spec/formtastic_spec.rb
Expand Up @@ -1540,7 +1540,7 @@ def custom(arg1, arg2, options = {})

it 'should have a label inside the wrapper' do
output_buffer.should have_tag('form li label')
output_buffer.should have_tag('form li label', /Post ids/)
output_buffer.should have_tag('form li label', /Post/)
output_buffer.should have_tag("form li label[@for='author_post_ids']")
end

Expand Down Expand Up @@ -1586,7 +1586,7 @@ def custom(arg1, arg2, options = {})

it 'should have a label inside the wrapper' do
output_buffer.should have_tag('form li label')
output_buffer.should have_tag('form li label', /Author ids/)
output_buffer.should have_tag('form li label', /Author/)
output_buffer.should have_tag("form li label[@for='post_author_ids']")
end

Expand Down

0 comments on commit d98197e

Please sign in to comment.