Permalink
Browse files

support :fidden_fields => :never for checkboxes_input. Closes #697 #702

  • Loading branch information...
dnagir committed Oct 2, 2011
1 parent 7f71bd9 commit 9bc96e0cf9e709c9dec3ba246a23791734062fca
Showing with 24 additions and 5 deletions.
  1. +8 −4 lib/formtastic/inputs/check_boxes_input.rb
  2. +16 −1 spec/inputs/check_boxes_input_spec.rb
@@ -109,9 +109,7 @@ def choice_html(choice)
end
def hidden_field_for_all
- show_fantom = options[:hidden_fields]
- show_fantom = true if show_fantom.nil?
- unless show_fantom
+ unless hidden_collection?
""
else
options = {}
@@ -122,7 +120,13 @@ def hidden_field_for_all
end
def hidden_fields?
- options[:hidden_fields]
+ render_hidden = options[:hidden_fields]
+ return false if render_hidden == :never
+ render_hidden
+ end
+
+ def hidden_collection?
+ options[:hidden_fields] != :never
end
def check_box_with_hidden_input(choice)
@@ -186,8 +186,23 @@
output_buffer.should_not have_tag("form li fieldset ol li label input[@type='hidden'][@value='']", :count => ::Post.all.length)
end
+ it 'should generate collection hidden input' do
+ output_buffer.should have_tag("form input[@type='hidden'][@name='author[post_ids][]']", :count => 1)
+ end
+ end
+
+ describe 'when :hidden_fields is set to :never' do
+ before do
+ @output_buffer = ''
+ mock_everything
+
+ concat(semantic_form_for(@fred) do |builder|
+ concat(builder.input(:posts, :as => :check_boxes, :value_as_class => true, :hidden_fields => :never))
+ end)
+ end
+
it 'should not generate any hidden inputs' do
- output_buffer.should_not have_tag("form li fieldset input[@type='hidden']")
+ output_buffer.should_not have_tag("form li input[@type='hidden']")
end
end

0 comments on commit 9bc96e0

Please sign in to comment.