diff --git a/lib/formtastic.rb b/lib/formtastic.rb index 96fddfb94..c582ee539 100644 --- a/lib/formtastic.rb +++ b/lib/formtastic.rb @@ -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 @@ -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. @@ -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 diff --git a/spec/inputs/check_boxes_input_spec.rb b/spec/inputs/check_boxes_input_spec.rb index cbcd22868..65bc19ab0 100644 --- a/spec/inputs/check_boxes_input_spec.rb +++ b/spec/inputs/check_boxes_input_spec.rb @@ -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 diff --git a/spec/inputs/radio_input_spec.rb b/spec/inputs/radio_input_spec.rb index 8a6a0d688..34ceb4813 100644 --- a/spec/inputs/radio_input_spec.rb +++ b/spec/inputs/radio_input_spec.rb @@ -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