Skip to content

Commit

Permalink
Merge pull request #730 from jslag/master
Browse files Browse the repository at this point in the history
Bring time input behavior in line with time_select when inputs are empty
  • Loading branch information
justinfrench committed Nov 15, 2011
2 parents 4a99a8a + 617ef95 commit 45ec7a7
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
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
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 45ec7a7

Please sign in to comment.