Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a configuration option to change the class of buttons. Closes #318

This changes the default behavior of having a fixed "button" class
on the buttons.
  • Loading branch information...
commit 1e1a2bb73f2819bfbb920cc34573de73badd33ca 1 parent 96275d6
@cfcosta cfcosta authored
View
4 lib/simple_form.rb
@@ -108,6 +108,10 @@ module SimpleForm
mattr_accessor :cache_discovery
@@cache_discovery = !Rails.env.development?
+ # Adds a class to each generated button, mostly for compatiblity
+ mattr_accessor :button_class
+ @@button_class = 'button'
+
## WRAPPER CONFIGURATION
@@wrappers = {}
View
2  lib/simple_form/form_builder.rb
@@ -193,7 +193,7 @@ def association(association, options={}, &block)
#
def button(type, *args, &block)
options = args.extract_options!
- options[:class] = "button #{options[:class]}".strip
+ options[:class] = "#{SimpleForm.button_class} #{options[:class]}".strip
args << options
if respond_to?("#{type}_button")
send("#{type}_button", *args, &block)
View
7 test/form_builder/button_test.rb
@@ -18,4 +18,11 @@ def with_button_for(object, *args)
with_button_for @user, :submit
assert_select 'form input.button[type=submit][value=Create User]'
end
+
+ test "builder should use the default class from the configuration" do
+ swap SimpleForm, :button_class => 'btn' do
+ with_button_for :post, :submit
+ assert_select 'form input.btn[type=submit][value=Save Post]'
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.