Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

propagate defaults options to nested forms, closes #533

  • Loading branch information...
commit 4b512be34a2c756bd9f95ef8107df5ef9458063f 1 parent 798a0a1
Vasiliy Ermolovich authored
3  lib/simple_form/action_view_extensions/builder.rb
@@ -193,7 +193,8 @@ def collection_check_boxes(attribute, collection, value_method, text_method, opt
193 193 # end
194 194 def simple_fields_for(*args, &block)
195 195 options = args.extract_options!
196   - options[:wrapper] ||= self.options[:wrapper]
  196 + options[:wrapper] ||= self.options[:wrapper]
  197 + options[:defaults] ||= self.options[:defaults]
197 198
198 199 if self.class < ActionView::Helpers::FormBuilder
199 200 options[:builder] ||= self.class
14 test/form_builder/general_test.rb
@@ -305,6 +305,20 @@ def with_custom_form_for(object, *args, &block)
305 305 assert_no_select "input.string[name='user[credit_limit]']"
306 306 end
307 307
  308 + test 'builder should receive a default argument and pass it to the inputs and nested form' do
  309 + @user.company = Company.new(1, 'Empresa')
  310 +
  311 + with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f|
  312 + concat(f.input :name)
  313 + concat(f.simple_fields_for(:company) do |company_form|
  314 + concat(company_form.input :name)
  315 + end)
  316 + end
  317 +
  318 + assert_select "input.string.default_class[name='user[name]']"
  319 + assert_select "input.string.default_class[name='user[company_attributes][name]']"
  320 + end
  321 +
308 322 # WITHOUT OBJECT
309 323 test 'builder should generate properly when object is not present' do
310 324 with_form_for :project, :name

0 comments on commit 4b512be

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