Merge pull request #999 from plataformatec/rm-boolean-label-class

Add boolean_label_class config
This commit is contained in:
Rafael Mendonça França 2014-03-12 17:31:10 -03:00
commit fee9277d8d
5 changed files with 30 additions and 2 deletions

View File

@ -8,6 +8,7 @@
* Add `include_default_input_wrapper_class` config [@luizcosta](https://github.com/luizcosta)
* Map `datetime`, `date` and `time` input types to their respective HTML5 input tags
when the `:html5` is set to `true` [@volmer](https://github.com/volmer)
* Add `boolean_label_class` config.
### bug fix
* Collection input that uses automatic collection translation properly sets checked values.

View File

@ -143,6 +143,9 @@ SimpleForm.setup do |config|
# Default class for inputs
# config.input_class = nil
# Define the default class of the input wrapper of the boolean input.
config.boolean_label_class = 'checkbox'
# Defines if the default input wrapper class should be included in radio
# collection wrappers.
# config.include_default_input_wrapper_class = true

View File

@ -157,6 +157,10 @@ module SimpleForm
mattr_accessor :include_default_input_wrapper_class
@@include_default_input_wrapper_class = true
# Define the default class of the input wrapper of the boolean input.
mattr_accessor :boolean_label_class
@@boolean_label_class = 'checkbox'
## WRAPPER CONFIGURATION
# The default wrapper to be used by the FormBuilder.
mattr_accessor :default_wrapper

View File

@ -4,7 +4,7 @@ module SimpleForm
def input
if nested_boolean_style?
build_hidden_field_for_checkbox +
template.label_tag(nil, class: "checkbox") {
template.label_tag(nil, class: SimpleForm.boolean_label_class) {
build_check_box_without_hidden_field + inline_label
}
else
@ -18,7 +18,7 @@ module SimpleForm
elsif nested_boolean_style?
html_options = label_html_options.dup
html_options[:class] ||= []
html_options[:class].push(:checkbox)
html_options[:class].push(SimpleForm.boolean_label_class) if SimpleForm.boolean_label_class
build_hidden_field_for_checkbox +
@builder.label(label_target, html_options) {

View File

@ -128,6 +128,16 @@ class BooleanInputTest < ActionView::TestCase
end
end
test 'input boolean with nested style works using :input only in wrapper config (no label_input), adding the extra label wrapper with custom class' do
swap_wrapper do
swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
with_input_for @user, :active, :boolean
assert_select 'label.boolean + input[type=hidden] + label.foo > input.boolean'
end
end
end
test 'input boolean with nested style works using :label_input in wrapper config, adding "checkbox" class to label' do
swap_wrapper :default, self.custom_wrapper_without_top_level do
swap SimpleForm, boolean_style: :nested do
@ -138,6 +148,16 @@ class BooleanInputTest < ActionView::TestCase
end
end
test 'input boolean with nested style works using :label_input in wrapper config, adding custom class to label' do
swap_wrapper :default, self.custom_wrapper_without_top_level do
swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
with_input_for @user, :active, :boolean
assert_select 'input[type=hidden] + label.boolean.foo > input.boolean'
end
end
end
test 'input boolean without additional classes should add "checkbox" class to label' do
swap_wrapper :default, self.custom_wrapper_without_top_level do
swap SimpleForm, boolean_style: :nested, generate_additional_classes_for: [:input] do