Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…s options, resolving issue #16.
  • Loading branch information...
commit 0db1251bc9049dc4c5e6a74f5cda5cc34a587ddf 1 parent a9bd9ec
José Valim josevalim authored
Showing with 14 additions and 10 deletions.
  1. +5 −1 lib/formtastic.rb
  2. +9 −9 spec/formtastic_spec.rb
6 lib/formtastic.rb
View
@@ -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)
18 spec/formtastic_spec.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.