Permalink
Browse files

inputs accept :for_options to pass down options to wrapped semantic_f…

…ields_for.

Signed-off-by: Justin French <justin@indent.com.au>
  • Loading branch information...
1 parent aba144d commit 164a70aa6b2b45bad3192cc32083617efded89d5 @josevalim josevalim committed with justinfrench Mar 16, 2009
Showing with 20 additions and 7 deletions.
  1. +9 −6 lib/formtastic.rb
  2. +11 −1 spec/formtastic_spec.rb
View
@@ -221,8 +221,8 @@ def inputs(*args, &block)
html_options[:class] ||= "inputs"
if fields_for_object = html_options.delete(:for)
- inputs_for_nested_attributes(fields_for_object, html_options.except(:name, :id, :class),
- args << html_options, &block)
+ inputs_for_nested_attributes(fields_for_object, args << html_options,
+ html_options.delete(:for_options) || {}, &block)
elsif block_given?
field_set_and_list_wrapping(html_options, &block)
else
@@ -296,17 +296,20 @@ def semantic_fields_for(record_or_name_or_array, *args, &block)
protected
- # Deals with :for option when it's supplied to inputs methods.
+ # Deals with :for option when it's supplied to inputs methods. Additional
+ # options to be passed down to :for should be supplied using :for_options
+ # key.
+ #
# It should raise an error if a block with arity zero is given.
#
- def inputs_for_nested_attributes(fields_for_object, options, inputs_args, &block)
+ def inputs_for_nested_attributes(fields_for_object, inputs, options, &block)
fields_for_block = if block_given?
raise ArgumentError, 'You gave :for option with a block to inputs method, ' <<
'but the block does not accept any argument.' if block.arity <= 0
- proc { |f| f.inputs(*inputs_args){ block.call(f) } }
+ proc { |f| f.inputs(*inputs){ block.call(f) } }
else
- proc { |f| f.inputs(*inputs_args) }
+ proc { |f| f.inputs(*inputs) }
end
semantic_fields_for(*(Array(fields_for_object) << options), &fields_for_block)
View
@@ -2254,11 +2254,21 @@ def custom(arg1, arg2, options = {})
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
semantic_form_for(@new_post) do |builder|
- builder.inputs :index => 10, :for => [:author, @bob] do |bob_builder|
+ builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
bob_builder.instance_variable_get('@default_options').should == { :index => 10 }
end
end
end
+
+ it 'should not add builder as a fieldset attribute tag' do
+ semantic_form_for(@new_post) do |builder|
+ builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
+ concat('input')
+ end
+ end
+
+ output_buffer.should_not have_tag('fieldset[@builder="Formtastic::SemanticFormHelper"]')
+ end
end
describe 'when a :name option is provided' do

0 comments on commit 164a70a

Please sign in to comment.