Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 9bc96e0cf9e709c9dec3ba246a23791734062fca 1 parent 7f71bd9
Dmytrii Nagirniak authored October 03, 2011
12  lib/formtastic/inputs/check_boxes_input.rb
@@ -109,9 +109,7 @@ def choice_html(choice)
109 109
       end
110 110
 
111 111
       def hidden_field_for_all
112  
-        show_fantom = options[:hidden_fields]
113  
-        show_fantom = true if show_fantom.nil?
114  
-        unless show_fantom
  112
+        unless hidden_collection?
115 113
           ""
116 114
         else
117 115
           options = {}
@@ -122,7 +120,13 @@ def hidden_field_for_all
122 120
       end
123 121
 
124 122
       def hidden_fields?
125  
-        options[:hidden_fields]
  123
+        render_hidden = options[:hidden_fields]
  124
+        return false if render_hidden == :never
  125
+        render_hidden
  126
+      end
  127
+
  128
+      def hidden_collection?
  129
+        options[:hidden_fields] != :never
126 130
       end
127 131
 
128 132
       def check_box_with_hidden_input(choice)
17  spec/inputs/check_boxes_input_spec.rb
@@ -186,8 +186,23 @@
186 186
         output_buffer.should_not have_tag("form li fieldset ol li label input[@type='hidden'][@value='']", :count => ::Post.all.length)
187 187
       end
188 188
 
  189
+      it 'should generate collection hidden input' do
  190
+        output_buffer.should have_tag("form input[@type='hidden'][@name='author[post_ids][]']", :count => 1)
  191
+      end
  192
+    end
  193
+
  194
+    describe 'when :hidden_fields is set to :never' do
  195
+      before do
  196
+        @output_buffer = ''
  197
+        mock_everything
  198
+
  199
+        concat(semantic_form_for(@fred) do |builder|
  200
+          concat(builder.input(:posts, :as => :check_boxes, :value_as_class => true, :hidden_fields => :never))
  201
+        end)
  202
+      end
  203
+
189 204
       it 'should not generate any hidden inputs' do
190  
-        output_buffer.should_not have_tag("form li fieldset input[@type='hidden']")
  205
+        output_buffer.should_not have_tag("form li input[@type='hidden']")
191 206
       end
192 207
     end
193 208
 

0 notes on commit 9bc96e0

Please sign in to comment.
Something went wrong with that request. Please try again.