1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Merge branch 'master' into ua-html-options

Conflicts:
	CHANGELOG.md
This commit is contained in:
Ulisses Herrera Freire de Almeida 2014-03-13 11:00:22 -03:00
commit c333ea7273
6 changed files with 30 additions and 6 deletions

View file

@ -11,10 +11,6 @@ gemfile:
- gemfiles/Gemfile.rails-4-0-stable
- gemfiles/Gemfile.rails-4-1-stable
- Gemfile
matrix:
allow_failures:
- gemfile: Gemfile
- gemfile: gemfiles/Gemfile.rails-4-1-stable
notifications:
email: false
campfire:

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.
* Add `:html` option to include additional attributes on custom wrappers [remofritzsche](https://github.com/remofritzsche) and [@ulissesalmeida](https://github.com/ulissesalmeida)
### bug fix

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