Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

propagate defaults options to nested forms, closes #533

  • Loading branch information...
commit 4b512be34a2c756bd9f95ef8107df5ef9458063f 1 parent 798a0a1
@nashby authored
View
3  lib/simple_form/action_view_extensions/builder.rb
@@ -193,7 +193,8 @@ def collection_check_boxes(attribute, collection, value_method, text_method, opt
# end
def simple_fields_for(*args, &block)
options = args.extract_options!
- options[:wrapper] ||= self.options[:wrapper]
+ options[:wrapper] ||= self.options[:wrapper]
+ options[:defaults] ||= self.options[:defaults]
if self.class < ActionView::Helpers::FormBuilder
options[:builder] ||= self.class
View
14 test/form_builder/general_test.rb
@@ -305,6 +305,20 @@ def with_custom_form_for(object, *args, &block)
assert_no_select "input.string[name='user[credit_limit]']"
end
+ test 'builder should receive a default argument and pass it to the inputs and nested form' do
+ @user.company = Company.new(1, 'Empresa')
+
+ with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
+ concat(f.input :name)
+ concat(f.simple_fields_for(:company) do |company_form|
+ concat(company_form.input :name)
+ end)
+ end
+
+ assert_select "input.string.default_class[name='user[name]']"
+ assert_select "input.string.default_class[name='user[company_attributes][name]']"
+ end
+
# WITHOUT OBJECT
test 'builder should generate properly when object is not present' do
with_form_for :project, :name

0 comments on commit 4b512be

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