Add rudimentary support to wrapper_tag.
This commit is contained in:
parent
d9cc0a3f94
commit
02f716717a
|
@ -26,4 +26,8 @@ module SimpleForm
|
|||
# Series of attemps to detect a default value method for collection
|
||||
mattr_accessor :collection_value_methods
|
||||
@@collection_value_methods = [ :id, :to_s ]
|
||||
|
||||
# You can wrap all inputs in a pre-defined tag. By default is nil.
|
||||
mattr_accessor :wrapper_tag
|
||||
@@wrapper_tag = nil
|
||||
end
|
|
@ -11,11 +11,19 @@ module SimpleForm
|
|||
klass.new(self, attribute, input_type, options).generate
|
||||
end
|
||||
|
||||
pieces.compact.join
|
||||
wrap_content(pieces.compact.join)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def wrap_content(content)
|
||||
if SimpleForm.wrapper_tag
|
||||
@template.content_tag(SimpleForm.wrapper_tag, content)
|
||||
else
|
||||
content
|
||||
end
|
||||
end
|
||||
|
||||
def default_input_type(attribute, options)
|
||||
return options[:as].to_sym if options[:as]
|
||||
return :select if options[:collection]
|
||||
|
|
|
@ -128,4 +128,13 @@ class FormBuilderTest < ActionView::TestCase
|
|||
with_form_for :name, :error => false
|
||||
assert_no_select 'span.error'
|
||||
end
|
||||
|
||||
test 'builder support wrapping around an specific tag' do
|
||||
swap SimpleForm, :wrapper_tag => :p do
|
||||
with_form_for :name
|
||||
assert_select 'form p label[for=user_name]'
|
||||
assert_select 'form p input#user_name.string'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue