Skip to content

Commit

Permalink
Refactor label logic to generate "for" attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed Dec 3, 2011
1 parent 7eb55ff commit 379ae58
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/simple_form/components/labels.rb
Expand Up @@ -22,8 +22,11 @@ def translate_required_mark
end

def label
return template.label_tag(nil, label_text, label_html_options) if [:check_boxes, :radio].include?(input_type)
@builder.label(label_target, label_text, label_html_options)
if input_type_should_generate_for_attribute?
@builder.label(label_target, label_text, label_html_options)
else
template.label_tag(nil, label_text, label_html_options)
end
end

def label_text
Expand Down Expand Up @@ -65,6 +68,10 @@ def label_translation #:nodoc:
attribute_name.to_s.humanize
end
end

def input_type_should_generate_for_attribute?
[:check_boxes, :radio].exclude?(input_type)
end
end
end
end

0 comments on commit 379ae58

Please sign in to comment.