Merge pull request #536 from nashby/fix-issue-533
propagate defaults options to nested forms
This commit is contained in:
commit
fad3d1408a
|
@ -193,7 +193,8 @@ module SimpleForm
|
|||
# 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
|
||||
|
|
|
@ -305,6 +305,20 @@ class FormBuilderTest < ActionView::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue