Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add easier method of suppressing labels on timeish inputs

  • Loading branch information...
commit 9dbb8e57864dd4c27d679b4da0c1be3f218ab968 1 parent 4158d19
@jpmckinney jpmckinney authored
View
6 lib/formtastic/inputs/base/timeish.rb
@@ -130,8 +130,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])
View
8 spec/inputs/date_select_input_spec.rb
@@ -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
View
8 spec/inputs/datetime_select_input_spec.rb
@@ -156,6 +156,14 @@
output_buffer.should_not include(">")
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
View
10 spec/inputs/time_select_input_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.