never render fantom hidden input (should close #697) #702

Closed
wants to merge 2 commits into
from
@@ -109,7 +109,7 @@ def choice_html(choice)
end
def hidden_field_for_all
- if hidden_fields?
+ unless hidden_collection?
""
else
options = {}
@@ -120,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)
@@ -185,6 +185,25 @@
it 'should not generate empty hidden inputs' do
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 input[@type='hidden']")
+ end
end
describe 'when :disabled is set' do