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.
This commit is contained in:
Cainã Costa 2011-09-11 23:14:39 -03:00
parent 96275d6241
commit 1e1a2bb73f
3 changed files with 12 additions and 1 deletions

View File

@ -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 File

@ -193,7 +193,7 @@ module SimpleForm
#
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 File

@ -18,4 +18,11 @@ class ButtonTest < ActionView::TestCase
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