Permalink
Browse files

Just show blank option if neither include blank and prompt are sent a…

…s options, resolving issue #16.
  • Loading branch information...
1 parent a9bd9ec commit 0db1251bc9049dc4c5e6a74f5cda5cc34a587ddf @josevalim josevalim committed May 31, 2009
Showing with 14 additions and 10 deletions.
  1. +5 −1 lib/formtastic.rb
  2. +9 −9 spec/formtastic_spec.rb
View
6 lib/formtastic.rb
@@ -554,10 +554,14 @@ def hidden_input(method, options)
#
# By default, all select inputs will have a blank option at the top of the list. You can add
# a prompt with the :prompt option, or disable the blank option with :include_blank => false.
+ #
def select_input(method, options)
collection = find_collection_for_column(method, options)
html_options = options.delete(:input_html) || {}
- options[:include_blank] ||= true
+
+ unless options.key?(:include_blank) || options.key?(:prompt)
+ options[:include_blank] = true
+ end
reflection = find_reflection(method)
if reflection && [ :has_many, :has_and_belongs_to_many ].include?(reflection.macro)
View
18 spec/formtastic_spec.rb
@@ -1511,7 +1511,7 @@ def custom(arg1, arg2, options = {})
end
it 'should have a blank option by default' do
- output_buffer.should have_tag("form li select option[@value='']", //)
+ output_buffer.should have_tag("form li select option[@value='']", "")
end
end
@@ -1524,25 +1524,25 @@ def custom(arg1, arg2, options = {})
end
it 'should not have a blank option' do
- output_buffer.should have_tag("form li select option[@value='']", //)
+ output_buffer.should_not have_tag("form li select option[@value='']", "")
end
end
-
- describe 'when :include_blank => true and :prompt => "choose something" is set' do
+
+ describe 'when :prompt => "choose something" 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, :include_blank => true, :prompt => "choose author"))
+ concat(builder.input(:author, :as => :select, :prompt => "choose author"))
end
end
- it 'should have a blank select option' do
- output_buffer.should have_tag("form li select option[@value='']", //)
- end
-
it 'should have a select with prompt' do
output_buffer.should have_tag("form li select option[@value='']", /choose author/)
end
+
+ it 'should not have a blank select option' do
+ output_buffer.should_not have_tag("form li select option[@value='']", "")
+ end
end
describe 'when no object is given' do

0 comments on commit 0db1251

Please sign in to comment.