Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix issue #331, :label=>false on checkboxes/radiobuttons

  • Loading branch information...
commit 214135dc740ec060b461ca8423cf60e9d117a23f 1 parent a53315a
@coreyhaines coreyhaines authored yabawock committed
View
17 lib/formtastic.rb
@@ -907,10 +907,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
@@ -1187,9 +1184,7 @@ def check_boxes_input(method, options)
template.content_tag(:li, Formtastic::Util.html_safe(li_content), li_options)
end
- fieldset_content = template.content_tag(:legend,
- template.label_tag(nil, localized_string(method, options[:label], :label) || humanized_attribute_name(method), :for => nil), :class => :label
- )
+ fieldset_content = legend_tag(method, options)
fieldset_content << self.create_hidden_field_for_check_boxes(input_name, value_as_class) unless hidden_fields
fieldset_content << template.content_tag(:ol, Formtastic::Util.html_safe(list_item_content.join))
template.content_tag(:fieldset, fieldset_content)
@@ -1409,6 +1404,14 @@ 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
View
15 spec/inputs/check_boxes_input_spec.rb
@@ -356,6 +356,21 @@
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)
+ @form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:authors, :as => :check_boxes, :label => false))
+ end
+ end
+
+ it "should not output the legend" do
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
+ output_buffer.should_not have_tag("legend.label")
+ end
+ end
end
describe 'for a has_and_belongs_to_many association' do
View
15 spec/inputs/radio_input_spec.rb
@@ -225,4 +225,19 @@
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)
+ @form = 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.concat(@form) if Formtastic::Util.rails3?
+ output_buffer.should_not have_tag("legend.label")
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.