Skip to content


Allow to override form class with custom class! html attribute Implementation for #116 #639

wants to merge 1 commit into from

5 participants


No description provided.


Thank you for the pull request.

I don't like the use of a hash key with a !. But I don't have any idea how to make this now.

Lets see what the others think. cc @josevalim @carlosantoniodasilva @lucasmazza


Yeah, I kinda dislike the bang thing as well =(.

We've had a similar request (someone using the mailing I think), but for overriding hint class for a particular input instead. Perhaps we can come up with something that solves both in a similar approach (I know they're rather different code, but the idea persists).

Lets try to keep this on hold for a while to see if new ideas come up.

@AndreyChernyh thanks.


I really should have checked to see if someone had tried this already. :laughing: #657

Guess we are in need of a Wiki page showing a better solution.


@ootoovak a wiki page sounds a good option, you can go ahead and create one if you want with that code snippet and more examples if necessary, the wiki is open to everyone. Thanks!


This is a great pull request. If bang is a problem, we can use :force_class or :only_class instead


I'm closing this one for the same reason as #657. If you want to have a class different for your forms you should not set in the global config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
7 lib/simple_form/action_view_extensions/form_helper.rb
@@ -23,7 +23,10 @@ def simple_form_for(record, options={}, &block)
unless options[:html].key?(:novalidate)
options[:html][:novalidate] = !SimpleForm.browser_validations
- options[:html][:class] = [SimpleForm.form_class, simple_form_css_class(record, options)].compact.join(" ")
+ html_classes = []
+ html_classes << SimpleForm.form_class unless options[:html].key?(:class!)
+ html_classes << simple_form_css_class(record, options)
+ options[:html][:class] = html_classes.compact.join(" ")
with_simple_form_field_error_proc do
form_for(record, options, &block)
@@ -57,6 +60,8 @@ def simple_form_css_class(record, options)
if html_options.key?(:class)
+ elsif html_options.key?(:class!)
+ html_options.delete(:class!)
elsif record.is_a?(String) || record.is_a?(Symbol)
as || record
5 test/action_view_extensions/form_helper_test.rb
@@ -79,6 +79,11 @@ class FormHelperTest < ActionView::TestCase
assert_select 'form.my_class'
+ test 'SimpleForm should override form class if class! is specified' do
+ with_concat_form_for(:user, :html => {:class! => 'only_class'})
+ assert_select "form[class='only_class']"
+ end
test 'pass options to SimpleForm' do
with_concat_form_for(:user, :url => '/account', :html => { :id => 'my_form' })
assert_select 'form#my_form'
Something went wrong with that request. Please try again.