Permalink
Browse files

Add configuration to add class globally to inputs.

Closes #316
  • Loading branch information...
1 parent c30d832 commit 7ff302b6e5c99a34338fb6ba4811021dba931d41 @rafaelfranca rafaelfranca committed Sep 27, 2011
@@ -85,4 +85,7 @@
# Default class for buttons
# config.button_class = 'button'
+
+ # Default class for inputs
+ # config.input_class = nil
end
View
@@ -112,6 +112,10 @@ module SimpleForm
mattr_accessor :button_class
@@button_class = 'button'
+ # Adds a class to each generated inputs
+ mattr_accessor :input_class
+ @@input_class = nil
+
## WRAPPER CONFIGURATION
@@wrappers = {}
@@ -166,4 +170,4 @@ def self.setup
"Updating to the new API is easy and fast. Check for more info here: https://github.com/plataformatec/simple_form/wiki/Upgrading-to-Simple-Form-2.0"
end
end
-end
+end
@@ -58,7 +58,7 @@ def input_options
end
def input_html_classes
- [input_type, required_class, disabled_class].compact
+ [input_type, required_class, disabled_class, input_class].compact
end
def has_autofocus?
@@ -75,6 +75,12 @@ def limit
column && column.limit
end
+ def input_class
+ return if options[:input_class] == false
+
+ SimpleForm.input_class
+ end
+
# Find reflection name when available, otherwise use attribute
def reflection_or_attribute_name
reflection ? reflection.name : attribute_name
@@ -15,6 +15,20 @@ class InputTest < ActionView::TestCase
assert_select 'select.datetime'
end
+ test 'input should accepts input class configuration' do
+ swap SimpleForm, :input_class => :xlarge do
+ with_input_for @user, :name, :string
+ assert_select 'input.xlarge'
+ end
+ end
+
+ test 'input should disable the input class configuration with an option' do
+ swap SimpleForm, :input_class => :xlarge do
+ with_input_for @user, :name, :string, :input_class => false
+ assert_no_select 'input.xlarge'
+ end
+ end
+
test 'input should generate autofocus attribute based on the autofocus option' do
with_input_for @user, :name, :string, :autofocus => true
assert_select 'input.string[autofocus]'

0 comments on commit 7ff302b

Please sign in to comment.