Permalink
Browse files

improved around showing multiple or single selects, ref #745

  • Loading branch information...
justinfrench committed Dec 12, 2011
1 parent c36692c commit 5eef0ee56b108e0d82737fa5023586d96a74ee60
Showing with 25 additions and 5 deletions.
  1. +9 −5 lib/formtastic/inputs/select_input.rb
  2. +16 −0 spec/inputs/select_input_spec.rb
@@ -86,7 +86,9 @@ module Inputs
# </fieldset>
# </form>
#
- # @example Override Formtastic's assumption on when you need a multi select
+ # @example Override Formtastic's assumption on when you need a multi select (either works):
+ # <%= f.input :authors, :as => :select, :multiple => true %>
+ # <%= f.input :authors, :as => :select, :multiple => false %>
# <%= f.input :authors, :as => :select, :input_html => { :multiple => true } %>
# <%= f.input :authors, :as => :select, :input_html => { :multiple => false } %>
#
@@ -207,13 +209,15 @@ def multiple_by_association?
end
def multiple_by_options?
- options[:multiple] || (options[:input_html] && options[:input_html][:multiple])
+ return options[:multiple] if options.key?(:multiple)
+ return options[:input_html][:multiple] if options.key?(:input_html) && options[:input_html].key?(:multiple)
end
-
+
def multiple?
- multiple_by_options? || multiple_by_association?
+ return multiple_by_options? unless multiple_by_options?.nil?
+ multiple_by_association?
end
-
+
def single?
!multiple?
end
@@ -387,6 +387,22 @@
it 'should have a multi-select select' do
output_buffer.should have_tag('form li select[@multiple="multiple"]')
end
+
+ it 'should allow non-multi select with the :multiple option' do
+ output_buffer.replace ''
+ concat(semantic_form_for(@freds_post) do |builder|
+ concat(builder.input(:authors, :as => :select, :multiple => false))
+ end)
+ output_buffer.should_not have_tag('form li select[@multiple="multiple"]')
+ end
+
+ it 'should allow non-multi select with the :input_html option' do
+ output_buffer.replace ''
+ concat(semantic_form_for(@freds_post) do |builder|
+ concat(builder.input(:authors, :as => :select, :input_html => { :multiple => false }))
+ end)
+ output_buffer.should_not have_tag('form li select[@multiple="multiple"]')
+ end
it 'should have a select option for each Author' do
output_buffer.should have_tag('form li select option', :count => ::Author.all.size)

0 comments on commit 5eef0ee

Please sign in to comment.