From 0dd61968a9e9658b23fef8835d8ea2e2e20f3bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 10 Dec 2009 23:21:22 -0200 Subject: [PATCH] Allow wrapper tag to be given on demand. --- TODO.rdoc | 3 --- lib/simple_form/components/wrapper.rb | 6 ++++-- test/form_builder_test.rb | 7 +++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/TODO.rdoc b/TODO.rdoc index e1dca46c..18708aa0 100644 --- a/TODO.rdoc +++ b/TODO.rdoc @@ -1,13 +1,10 @@ == General * Sample CSS -* Get default string options from column definition * Add support to default :prompt methods on datetime inputs * Add support to default label method -* Add support to f.label, f.error and f.hint calls * Improve readme with examples * :country, :time_zone, :group and :file types support -* Allow required to come after or before the label == Associations diff --git a/lib/simple_form/components/wrapper.rb b/lib/simple_form/components/wrapper.rb index d06473c0..2db6f2ab 100644 --- a/lib/simple_form/components/wrapper.rb +++ b/lib/simple_form/components/wrapper.rb @@ -6,8 +6,10 @@ module SimpleForm include RequiredHelpers def call - if SimpleForm.wrapper_tag - template.content_tag(SimpleForm.wrapper_tag, @component.call, component_html_options) + tag = options[:wrapper] || SimpleForm.wrapper_tag + + if tag + template.content_tag(tag, @component.call, component_html_options) else @component.call end diff --git a/test/form_builder_test.rb b/test/form_builder_test.rb index c7d48e53..eadb2a8e 100644 --- a/test/form_builder_test.rb +++ b/test/form_builder_test.rb @@ -160,6 +160,13 @@ class FormBuilderTest < ActionView::TestCase end end + test 'builder allows wrapper tag to be given on demand' do + simple_form_for @user do |f| + concat f.input :name, :wrapper => :b + end + assert_select 'form b.required.string' + end + test 'nested simple fields should yields an instance of FormBuilder' do simple_form_for :user do |f| f.simple_fields_for :posts do |posts_form|