From 8dbcd5be43448e8a34022980deac6fce620e0a63 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sun, 22 Jul 2012 00:38:57 +0300 Subject: [PATCH] allow to add additional classes only for wrapper closes #629 --- lib/simple_form/inputs/base.rb | 8 +++++--- lib/simple_form/wrappers/root.rb | 2 +- test/form_builder/general_test.rb | 9 +++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index 0780469c..f71e2b9e 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -60,9 +60,7 @@ module SimpleForm # 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 @@ module SimpleForm options end + def additional_classes + [input_type, required_class, readonly_class, disabled_class].compact + end + private def add_size! diff --git a/lib/simple_form/wrappers/root.rb b/lib/simple_form/wrappers/root.rb index de8537c5..0c59b032 100644 --- a/lib/simple_form/wrappers/root.rb +++ b/lib/simple_form/wrappers/root.rb @@ -24,7 +24,7 @@ module SimpleForm 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 diff --git a/test/form_builder/general_test.rb b/test/form_builder/general_test.rb index b8330005..19de68bc 100644 --- a/test/form_builder/general_test.rb +++ b/test/form_builder/general_test.rb @@ -46,6 +46,15 @@ class FormBuilderTest < ActionView::TestCase 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