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:
parent
96275d6241
commit
1e1a2bb73f
|
@ -108,6 +108,10 @@ module SimpleForm
|
||||||
mattr_accessor :cache_discovery
|
mattr_accessor :cache_discovery
|
||||||
@@cache_discovery = !Rails.env.development?
|
@@cache_discovery = !Rails.env.development?
|
||||||
|
|
||||||
|
# Adds a class to each generated button, mostly for compatiblity
|
||||||
|
mattr_accessor :button_class
|
||||||
|
@@button_class = 'button'
|
||||||
|
|
||||||
## WRAPPER CONFIGURATION
|
## WRAPPER CONFIGURATION
|
||||||
@@wrappers = {}
|
@@wrappers = {}
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ module SimpleForm
|
||||||
#
|
#
|
||||||
def button(type, *args, &block)
|
def button(type, *args, &block)
|
||||||
options = args.extract_options!
|
options = args.extract_options!
|
||||||
options[:class] = "button #{options[:class]}".strip
|
options[:class] = "#{SimpleForm.button_class} #{options[:class]}".strip
|
||||||
args << options
|
args << options
|
||||||
if respond_to?("#{type}_button")
|
if respond_to?("#{type}_button")
|
||||||
send("#{type}_button", *args, &block)
|
send("#{type}_button", *args, &block)
|
||||||
|
|
|
@ -18,4 +18,11 @@ class ButtonTest < ActionView::TestCase
|
||||||
with_button_for @user, :submit
|
with_button_for @user, :submit
|
||||||
assert_select 'form input.button[type=submit][value=Create User]'
|
assert_select 'form input.button[type=submit][value=Create User]'
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue