Skip to content
Browse files

Document that you can override `input_html_classes` in custom inputs.

Closes #539
  • Loading branch information...
1 parent a3cafca commit 45ae549ec32c0f4bf8c73bb9569f46ea4f0e92fa @rafaelfranca rafaelfranca committed Apr 21, 2012
Showing with 26 additions and 1 deletion.
  1. +11 −0 README.md
  2. +9 −1 test/inputs/discovery_test.rb
  3. +6 −0 test/support/discovery_inputs.rb
View
11 README.md
@@ -466,6 +466,17 @@ class DateTimeInput < SimpleForm::Inputs::DateTimeInput
end
```
+Or if you want to add a class to all the select fields you can do:
+
+```ruby
+# app/inputs/collection_select_input.rb
+class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
+ def input_html_classes
+ super.push('chosen')
+ end
+end
+```
+
## Custom form builder
You can create a custom form builder that uses **SimpleForm**.
View
10 test/inputs/discovery_test.rb
@@ -12,6 +12,7 @@ def discovery(value=false)
Object.send :remove_const, :StringInput
Object.send :remove_const, :NumericInput
Object.send :remove_const, :CustomizedInput
+ Object.send :remove_const, :CollectionSelectInput
end
end
end
@@ -58,4 +59,11 @@ def discovery(value=false)
assert_select 'form section input#user_age.numeric.integer'
end
end
-end
+
+ test 'new inputs can override the input_html_options' do
+ discovery do
+ with_form_for @user, :active, :as => :select
+ assert_select 'form select#user_active.select.chosen'
+ end
+ end
+end
View
6 test/support/discovery_inputs.rb
@@ -19,3 +19,9 @@ def input_method
:text_field
end
end
+
+class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
+ def input_html_classes
+ super.push('chosen')
+ end
+end

0 comments on commit 45ae549

Please sign in to comment.
Something went wrong with that request. Please try again.