Skip to content

Commit

Permalink
add field_with_hint class to the input with hint wrappers, closes hea…
Browse files Browse the repository at this point in the history
  • Loading branch information
nashby committed Jan 9, 2012
1 parent 25f8c81 commit 40a0b2a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
Expand Up @@ -4,7 +4,7 @@
# You can remove any component from the wrapper, change the order or even # 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 # add your own to the stack. The options given to the wrappers method
# are used to wrap the whole input. # 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 ## Extensions
# Determines whether to use HTML5 (:email, :url, :search, :tel) and required attributes # Determines whether to use HTML5 (:email, :url, :search, :tel) and required attributes
b.use :html5 b.use :html5
Expand Down
2 changes: 1 addition & 1 deletion lib/simple_form.rb
Expand Up @@ -144,7 +144,7 @@ def self.build(options={})
SimpleForm::Wrappers::Root.new(builder.to_a, options) SimpleForm::Wrappers::Root.new(builder.to_a, options)
end 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 :html5


b.use :min_max b.use :min_max
Expand Down
1 change: 1 addition & 0 deletions lib/simple_form/wrappers/root.rb
Expand Up @@ -26,6 +26,7 @@ def html_classes(input, options)
css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class] css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
css += input.html_classes css += input.html_classes
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors? css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.hint
css css
end end
end end
Expand Down
5 changes: 5 additions & 0 deletions test/form_builder/wrapper_test.rb
Expand Up @@ -16,6 +16,11 @@ class WrapperTest < ActionView::TestCase
assert_select 'div.field_with_errors' assert_select 'div.field_with_errors'
end 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 test 'wrapper should not have disabled class by default' do
with_form_for @user, :active with_form_for @user, :active
assert_no_select 'div.disabled' assert_no_select 'div.disabled'
Expand Down

0 comments on commit 40a0b2a

Please sign in to comment.