Provide named helpers.
This commit is contained in:
parent
bf4d766fcb
commit
1867275551
|
@ -22,7 +22,7 @@ module SimpleForm
|
|||
|
||||
def initialize(*) #:nodoc:
|
||||
super
|
||||
@wrapper = SimpleForm.wrapper(options.delete(:wrapper) || :default)
|
||||
@wrapper = SimpleForm.wrapper(options[:wrapper] || :default)
|
||||
end
|
||||
|
||||
# Basic input helper, combines all components in the stack to generate
|
||||
|
@ -91,7 +91,14 @@ module SimpleForm
|
|||
# given SimpleForm.time_zone_priority and SimpleForm.country_priority are used respectivelly.
|
||||
#
|
||||
def input(attribute_name, options={}, &block)
|
||||
wrapper.render find_input(attribute_name, options, &block)
|
||||
chosen =
|
||||
if name = options[:wrapper]
|
||||
name.is_a?(Symbol) ? SimpleForm.wrapper(name) : name
|
||||
else
|
||||
wrapper
|
||||
end
|
||||
|
||||
chosen.render find_input(attribute_name, options, &block)
|
||||
end
|
||||
alias :attribute :input
|
||||
|
||||
|
|
|
@ -20,10 +20,10 @@ class WrapperTest < ActionView::TestCase
|
|||
with_form_for @user, :active
|
||||
assert_no_select 'div.disabled'
|
||||
end
|
||||
|
||||
|
||||
test 'wrapper should support no wrapping when wrapper is false' do
|
||||
with_form_for @user, :name, :wrapper => false
|
||||
assert_select 'form > label[for=user_name]'
|
||||
with_form_for @user, :name, :wrapper => false
|
||||
assert_select 'form > label[for=user_name]'
|
||||
assert_select 'form > input#user_name.string'
|
||||
end
|
||||
|
||||
|
@ -71,4 +71,34 @@ class WrapperTest < ActionView::TestCase
|
|||
assert_select "section.custom_wrapper div.error_wrapper span.omg_error"
|
||||
end
|
||||
end
|
||||
|
||||
test 'custom wrappers on a form basis' do
|
||||
swap_wrapper :another do
|
||||
concat simple_form_for(@user) { |f|
|
||||
f.input :name
|
||||
}
|
||||
|
||||
assert_no_select "section.custom_wrapper div.another_wrapper label"
|
||||
assert_no_select "section.custom_wrapper div.another_wrapper input.string"
|
||||
|
||||
concat simple_form_for(@user, :wrapper => :another) { |f|
|
||||
f.input :name
|
||||
}
|
||||
|
||||
assert_select "section.custom_wrapper div.another_wrapper label"
|
||||
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
||||
end
|
||||
end
|
||||
|
||||
test 'custom wrappers on input basis' do
|
||||
swap_wrapper :another do
|
||||
with_form_for @user, :name
|
||||
assert_no_select "section.custom_wrapper div.another_wrapper label"
|
||||
assert_no_select "section.custom_wrapper div.another_wrapper input.string"
|
||||
|
||||
with_form_for @user, :name, :wrapper => :another
|
||||
assert_select "section.custom_wrapper div.another_wrapper label"
|
||||
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue