Skip to content

Commit

Permalink
Support empty Time inputs
Browse files Browse the repository at this point in the history
Before this change, it wasn't possible to create an input of type 'time'
that didn't default to the current date. This made it impossible to
differentiate between a form submission wherein the user hadn't picked a
date, and one in which they'd picked midnight UTC.
  • Loading branch information
jslag committed Oct 27, 2011
1 parent 0566774 commit 617ef95
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/formtastic/inputs/time_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ def fragments
time_fragments
end

def value_or_default_value
value ? value : Time.current
end

def fragment_value(fragment)
value_or_default_value.send(fragment)
value ? value.send(fragment) : ""
end

def hidden_fragments
Expand All @@ -43,4 +39,4 @@ def hidden_field_name(fragment)

end
end
end
end
27 changes: 27 additions & 0 deletions spec/inputs/time_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,33 @@

end

describe "with :ignore_date => false and no initial Time" do
before do
@new_post.stub(:publish_at)
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:publish_at, :as => :time, :ignore_date => false))
end)
end

it 'should have a hidden input for day, month and year' do
output_buffer.should have_tag('input#post_publish_at_1i')
output_buffer.should have_tag('input#post_publish_at_2i')
output_buffer.should have_tag('input#post_publish_at_3i')
end

it 'should not have values in hidden inputs for day, month and year' do
output_buffer.should have_tag('input#post_publish_at_1i[@value=""]')
output_buffer.should have_tag('input#post_publish_at_2i[@value=""]')
output_buffer.should have_tag('input#post_publish_at_3i[@value=""]')
end

it 'should have an select for hour and minute' do
output_buffer.should have_tag('select#post_publish_at_4i')
output_buffer.should have_tag('select#post_publish_at_5i')
end

end

describe "without seconds" do
before do
concat(semantic_form_for(@new_post) do |builder|
Expand Down

0 comments on commit 617ef95

Please sign in to comment.