diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index 38fc99da..54c49605 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -86,14 +86,7 @@ module SimpleForm # given SimpleForm.time_zone_priority and SimpleForm.country_priority are used respectivelly. # def input(attribute_name, options={}, &block) - column = find_attribute_column(attribute_name) - input_type = default_input_type(attribute_name, column, options) - - if block_given? - SimpleForm.components.render SimpleForm::Inputs::BlockInput.new(self, attribute_name, column, input_type, options, &block) - else - SimpleForm.components.render find_mapping(input_type).new(self, attribute_name, column, input_type, options) - end + SimpleForm.components.render find_input(attribute_name, options, &block) end alias :attribute :input @@ -113,8 +106,7 @@ module SimpleForm # def input_field(attribute_name, options={}) options[:input_html] = options.except(:as, :collection, :label_method, :value_method) - options.merge!(:components => [:input], :wrapper => false) - input(attribute_name, options) + SimpleForm::Wrappers::Root.new(:input, :wrapper => false).render find_input(attribute_name, options) end # Helper for dealing with association selects/radios, generating the @@ -296,6 +288,18 @@ module SimpleForm private + # Find an input based on the attribute name. + def find_input(attribute_name, options={}, &block) #:nodoc: + column = find_attribute_column(attribute_name) + input_type = default_input_type(attribute_name, column, options) + + if block_given? + SimpleForm::Inputs::BlockInput.new(self, attribute_name, column, input_type, options, &block) + else + find_mapping(input_type).new(self, attribute_name, column, input_type, options) + end + end + # Attempt to guess the better input type given the defined options. By # default alwayls fallback to the user :as option, or to a :select when a # collection is given. diff --git a/lib/simple_form/wrappers/many.rb b/lib/simple_form/wrappers/many.rb index 4b0d9dd6..8007e05f 100644 --- a/lib/simple_form/wrappers/many.rb +++ b/lib/simple_form/wrappers/many.rb @@ -12,7 +12,7 @@ module SimpleForm @defaults[:class] = Array.wrap(@defaults[:class]) end - def render(input, components = self.components) + def render(input) content = "".html_safe options = input.options diff --git a/lib/simple_form/wrappers/root.rb b/lib/simple_form/wrappers/root.rb index 7ac740f5..28205ea8 100644 --- a/lib/simple_form/wrappers/root.rb +++ b/lib/simple_form/wrappers/root.rb @@ -5,14 +5,6 @@ module SimpleForm super(:wrapper, *args) end - def render(input) - if components = input.options[:components] - super(input, SimpleForm::Wrappers.wrap(components)) - else - super - end - end - private def wrap(input, options, content) diff --git a/test/inputs_test.rb b/test/inputs_test.rb index f5ede621..0db706a6 100644 --- a/test/inputs_test.rb +++ b/test/inputs_test.rb @@ -104,32 +104,6 @@ class InputTest < ActionView::TestCase end end - test 'input should render components according to an optional :components option' do - with_input_for @user, :name, :string, :components => [:input, :label] - assert_select 'input + label' - - with_input_for @user, :age, :integer, :components => [:input, :label] - assert_select 'input + label' - - with_input_for @user, :active, :boolean, :components => [:label, :input] - assert_select 'label + input' - - with_input_for @user, :description, :text, :components => [:input, :label] - assert_select 'textarea + label' - - with_input_for @user, :password, :password, :components => [:input, :label] - assert_select 'input + label' - - with_input_for @user, :name, :file, :components => [:input, :label] - assert_select 'input + label' - - with_input_for @user, :country, :country, :components => [:input, :label] - assert_select 'select + label' - - with_input_for @user, :time_zone, :time_zone, :components => [:input, :label] - assert_select 'select + label' - end - # StringInput test 'input should map text field to string attribute' do with_input_for @user, :name, :string