Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: justinfrench/formtastic
...
head fork: darkliquid/formtastic
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
2  lib/formtastic.rb
@@ -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 = []
View
11 spec/inputs/date_input_spec.rb
@@ -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
View
11 spec/inputs/datetime_input_spec.rb
@@ -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
View
11 spec/inputs/time_input_spec.rb
@@ -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.