Permalink
Browse files

added some documentation and beefed up specs for the :selected option…

… on a :select input
  • Loading branch information...
justinfrench committed Oct 26, 2009
1 parent 9ef91e8 commit 70755b470ed14cc26b2b723a6521d90ba864cecc
Showing with 27 additions and 0 deletions.
  1. +7 −0 lib/formtastic.rb
  2. +20 −0 spec/input_spec.rb
View
@@ -585,6 +585,13 @@ def hidden_input(method, options)
# f.input :author, :value_method => :login
# f.input :author, :value_method => Proc.new { |a| "author_#{a.login}" }
#
+ # You can pre-select a specific option value by passing in the :select option.
+ #
+ # Examples:
+ #
+ # f.input :author, :selected => current_user.id
+ # f.input :author, :value_method => :login, :selected => current_user.login
+ #
# You can pass html_options to the select tag using :input_html => {}
#
# Examples:
View
@@ -1374,6 +1374,26 @@ def should_be_required(options)
end
end
end
+
+ describe 'when :selected is set' do
+ before do
+ @new_post.stub!(:author_id).and_return(nil)
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:author, :as => :select, :selected => @bob.id ))
+ end
+ end
+
+ it 'should have a selected item' do
+ output_buffer.should have_tag("form li select option[@selected='selected']")
+ end
+
+ it 'bob should be selected' do
+ output_buffer.should have_tag("form li select option[@selected='selected']", /bob/i)
+ output_buffer.should have_tag("form li select option[@selected='selected'][@value='42']")
+ end
+
+ end
+
end
describe ':as => :check_boxes' do

0 comments on commit 70755b4

Please sign in to comment.