Merge pull request #405 from nashby/feature-323

add field_with_hint class to the input with hint wrappers
This commit is contained in:
Rafael Mendonça França 2012-01-09 11:38:57 -08:00
commit 0bca82c419
4 changed files with 8 additions and 2 deletions

View File

@ -4,7 +4,7 @@ SimpleForm.setup do |config|
# You can remove any component from the wrapper, change the order or even
# add your own to the stack. The options given to the wrappers method
# are used to wrap the whole input.
config.wrappers :class => :input, :error_class => :field_with_errors do |b|
config.wrappers :class => :input, :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
## Extensions
# Determines whether to use HTML5 (:email, :url, :search, :tel) and required attributes
b.use :html5

View File

@ -144,7 +144,7 @@ module SimpleForm
SimpleForm::Wrappers::Root.new(builder.to_a, options)
end
wrappers :class => :input, :error_class => :field_with_errors do |b|
wrappers :class => :input, :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
b.use :html5
b.use :min_max

View File

@ -26,6 +26,7 @@ module SimpleForm
css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
css += input.html_classes
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.hint
css
end
end

View File

@ -16,6 +16,11 @@ class WrapperTest < ActionView::TestCase
assert_select 'div.field_with_errors'
end
test 'wrapper should add hint class for attribute with a hint' do
with_form_for @user, :name, :hint => 'hint'
assert_select 'div.field_with_hint'
end
test 'wrapper should not have disabled class by default' do
with_form_for @user, :active
assert_no_select 'div.disabled'