Permalink
Browse files

allow to add additional classes only for wrapper

closes #629
  • Loading branch information...
1 parent 6d4af55 commit 8dbcd5be43448e8a34022980deac6fce620e0a63 @nashby committed Jul 21, 2012
Showing with 15 additions and 4 deletions.
  1. +5 −3 lib/simple_form/inputs/base.rb
  2. +1 −1 lib/simple_form/wrappers/root.rb
  3. +9 −0 test/form_builder/general_test.rb
View
8 lib/simple_form/inputs/base.rb
@@ -60,9 +60,7 @@ def initialize(builder, attribute_name, column, input_type, options = {})
# Notice that html_options_for receives a reference to input_html_classes.
# This means that classes added dynamically to input_html_classes will
# still propagate to input_html_options.
- @html_classes = SimpleForm.additional_classes_for(:input) {
- [input_type, required_class, readonly_class, disabled_class].compact
- }
+ @html_classes = SimpleForm.additional_classes_for(:input) { additional_classes }
@input_html_classes = @html_classes.dup
@input_html_options = html_options_for(:input, input_html_classes).tap do |o|
@@ -80,6 +78,10 @@ def input_options
options
end
+ def additional_classes
+ [input_type, required_class, readonly_class, disabled_class].compact
+ end
+
private
def add_size!
View
2 lib/simple_form/wrappers/root.rb
@@ -24,7 +24,7 @@ def find(name)
def html_classes(input, options)
css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
- css += SimpleForm.additional_classes_for(:wrapper) { input.html_classes }
+ css += SimpleForm.additional_classes_for(:wrapper) { input.additional_classes }
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.has_hint?
css.compact
View
9 test/form_builder/general_test.rb
@@ -46,6 +46,15 @@ def with_custom_form_for(object, *args, &block)
end
end
+ test 'builder should allow to add additional classes only for wrapper' do
+ swap SimpleForm, :generate_additional_classes_for => [:wrapper] do
+ with_form_for @user, :post_count
+ assert_no_select "form input#user_post_count.string"
+ assert_no_select "form label#user_post_count.string"
+ assert_select "form div.input.string"
+ end
+ end
+
test 'builder should allow adding custom input mappings for integer input types' do
swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
with_form_for @user, :lock_version

0 comments on commit 8dbcd5b

Please sign in to comment.