Skip to content

Commit

Permalink
Fix issue #331, :label=>false on checkboxes/radiobuttons
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyhaines authored and mjonuschat committed Aug 8, 2010
1 parent 89db185 commit d8df6bf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/formtastic.rb
Expand Up @@ -887,10 +887,7 @@ def radio_input(method, options)
end

template.content_tag(:fieldset,
template.content_tag(:legend,
template.label_tag(nil, localized_string(method, options[:label], :label) || humanized_attribute_name(method), :for => nil), :class => :label
) <<
template.content_tag(:ol, Formtastic::Util.html_safe(list_item_content.join))
legend_tag(method, options) << template.content_tag(:ol, Formtastic::Util.html_safe(list_item_content.join))
)
end
alias :boolean_radio_input :radio_input
Expand Down Expand Up @@ -1158,12 +1155,9 @@ def check_boxes_input(method, options)
template.content_tag(:li, Formtastic::Util.html_safe(li_content), li_options)
end

template.content_tag(:fieldset,
template.content_tag(:legend,
template.label_tag(nil, localized_string(method, options[:label], :label) || humanized_attribute_name(method), :for => nil), :class => :label
) <<
template.content_tag(:ol, Formtastic::Util.html_safe(list_item_content.join))
)
fieldset_content = legend_tag(method, options)
fieldset_content << template.content_tag(:ol, Formtastic::Util.html_safe(list_item_content.join))
template.content_tag(:fieldset, fieldset_content)
end

# Outputs a country select input, wrapping around a regular country_select helper.
Expand Down Expand Up @@ -1345,6 +1339,13 @@ def field_set_and_list_wrapping_for_method(method, options, contents) #:nodoc:
)
end

# Generates the legend for radiobuttons and checkboxes
def legend_tag(method, options = {})
(options[:label] == false) ? "" : template.content_tag(:legend,
template.label_tag(nil, localized_string(method, options[:label], :label) || humanized_attribute_name(method), :for => nil), :class => :label
)
end

# For methods that have a database column, take a best guess as to what the input method
# should be. In most cases, it will just return the column type (eg :string), but for special
# cases it will simplify (like the case of :integer, :float & :decimal to :numeric), or do
Expand Down
14 changes: 14 additions & 0 deletions spec/inputs/check_boxes_input_spec.rb
Expand Up @@ -277,6 +277,20 @@
output_buffer.should have_tag("legend.label label", /The authors/)
end
end

describe "when :label option is false" do
before do
@output_buffer = ''
@new_post.stub!(:author_ids).and_return(nil)
semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :label => false, :morton => true))
end
end

it "should not output the legend" do
output_buffer.should_not have_tag("legend.label")
end
end
end
end

14 changes: 14 additions & 0 deletions spec/inputs/radio_input_spec.rb
Expand Up @@ -207,4 +207,18 @@
output_buffer.should have_tag("legend.label label", /The authors/)
end
end

describe "when :label option is false" do
before do
@output_buffer = ''
@new_post.stub!(:author_ids).and_return(nil)
semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :radio, :label => false))
end
end

it "should not output the legend" do
output_buffer.should_not have_tag("legend.label")
end
end
end

0 comments on commit d8df6bf

Please sign in to comment.