Permalink
Browse files

Merge pull request #866 from jpmckinney/option_to_suppress_timeish_la…

…bels

Add easier method of suppressing labels on timeish inputs
  • Loading branch information...
2 parents 4158d19 + 8841408 commit f3928a66cbdb1ef349ec7c94b86474fb48214d01 @justinfrench committed Jul 9, 2012
@@ -65,6 +65,9 @@ module Base
# @example Change the labels for each fragment
# <%= f.input :publish_at, :as => :date_select, :labels => { :year => "Y", :month => "M", :day => "D" } %>
#
+ # @example Suppress the labels for all fragments
+ # <%= f.input :publish_at, :as => :date_select, :labels => false %>
+ #
# @example Skip a fragment (defaults to 1, skips all following fragments)
# <%= f.input :publish_at, :as => :datetime_select, :discard_minute => true %>
# <%= f.input :publish_at, :as => :datetime_select, :discard_hour => true %>
@@ -130,8 +133,10 @@ def fragment_wrapping_html_options
end
def fragment_label(fragment)
- labels_from_options = options[:labels] || {}
- if labels_from_options.key?(fragment)
+ labels_from_options = options.key?(:labels) ? options[:labels] : {}
+ if !labels_from_options
+ ''
+ elsif labels_from_options.key?(fragment)
labels_from_options[fragment]
else
::I18n.t(fragment.to_s, :default => fragment.to_s.humanize, :scope => [:datetime, :prompts])
@@ -147,6 +147,14 @@
end
end
+
+ it "should not display labels for any fields when :labels is falsy" do
+ output_buffer.replace ''
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:created_at, :as => :date_select, :labels => false))
+ end)
+ output_buffer.should have_tag('form li.date_select fieldset ol li label', :count => 0)
+ end
end
describe "when required" do
@@ -156,6 +156,14 @@
output_buffer.should_not include("&gt;")
end
end
+
+ it "should not display labels for any fields when :labels is falsy" do
+ output_buffer.replace ''
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:created_at, :as => :datetime_select, :labels => false))
+ end)
+ output_buffer.should have_tag('form li.datetime_select fieldset ol li label', :count => 0)
+ end
end
describe "when required" do
@@ -192,7 +192,7 @@
output_buffer.should have_tag('form li.time_select fieldset ol li label', /#{f}/i) unless field == f
end
end
-
+
it "should not render unsafe HTML when :labels[:#{field}] is false" do
output_buffer.replace ''
concat(semantic_form_for(@new_post) do |builder|
@@ -202,6 +202,14 @@
end
end
+
+ it "should not render labels when :labels is falsy" do
+ output_buffer.replace ''
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => false))
+ end)
+ output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => 0)
+ end
end
describe ':namespace option' do

0 comments on commit f3928a6

Please sign in to comment.