Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: justinfrench/formtastic
...
head fork: darkliquid/formtastic
  • 1 commit
  • 4 files changed
  • 0 commit comments
  • 1 contributor
2  lib/formtastic.rb
View
@@ -995,7 +995,7 @@ def date_or_datetime_input(method, options)
hidden_fields_capture = ""
datetime = options.key?(:selected) ? options[:selected] : Time.now # can't do an || because nil is an important value
- datetime = @object.send(method) if @object && @object.send(method) # object trumps :selected
+ datetime = @object.send(method) if !datetime.nil? && @object && @object.send(method) # object trumps :selected unless :selected explicitly nil
html_options = options.delete(:input_html) || {}
input_ids = []
11 spec/inputs/date_input_spec.rb
View
@@ -66,6 +66,17 @@
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='2012'][@selected]", :count => 1)
end
+
+ it "should select nothing if :selected is explicitly set to nil" do
+ output_buffer.replace ''
+ @new_post.stub!(:created_at => Time.mktime(2012))
+ with_deprecation_silenced do
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:created_at, :as => :date, :selected => nil))
+ end
+ end
+ output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 0)
+ end
end
describe 'when the object has no value' do
11 spec/inputs/datetime_input_spec.rb
View
@@ -177,6 +177,17 @@
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='2012'][@selected]", :count => 1)
end
+
+ it "should select nothing if :selected is explicitly set to nil" do
+ output_buffer.replace ''
+ @new_post.stub!(:created_at => Time.mktime(2012))
+ with_deprecation_silenced do
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:created_at, :as => :datetime, :selected => nil))
+ end
+ end
+ output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 0)
+ end
end
describe 'when the object has no value' do
11 spec/inputs/time_input_spec.rb
View
@@ -92,6 +92,17 @@
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@selected]", :count => 1)
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@value='21'][@selected]", :count => 1)
end
+
+ it "should select nothing if :selected is explicitly set to nil" do
+ output_buffer.replace ''
+ @new_post.stub!(:created_at => Time.mktime(2012, 11, 30, 21, 45))
+ with_deprecation_silenced do
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:created_at, :as => :time, :selected => nil))
+ end
+ end
+ output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 0)
+ end
end
describe 'when the object has no value' do

No commit comments for this range

Something went wrong with that request. Please try again.