diff --git a/CHANGELOG.md b/CHANGELOG.md index 12ac9226..2d0fae92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ ## 2.0.1 +### enhancements + * Add `:inline_label` configuration to nested booleans to display text inline with checkbox. ([@ehoch](https://github.com/ehoch)) + ### bug fix * Sanitaze html attributes to `label` method. ([@nashby](https://github.com/nashby)). Closes [#472](https://github.com/plataformatec/simple_form/issues/472) diff --git a/Gemfile.lock b/Gemfile.lock index d4c1823e..547495b5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -72,4 +72,4 @@ DEPENDENCIES rake rdoc simple_form! - tzinfo + tzinfo \ No newline at end of file diff --git a/lib/simple_form/inputs/boolean_input.rb b/lib/simple_form/inputs/boolean_input.rb index 7ada93f1..62a7839f 100644 --- a/lib/simple_form/inputs/boolean_input.rb +++ b/lib/simple_form/inputs/boolean_input.rb @@ -5,7 +5,7 @@ module SimpleForm if nested_boolean_style? build_hidden_field_for_checkbox + template.label_tag(nil, :class => "checkbox") { - build_check_box_without_hidden_field + build_check_box_without_hidden_field + options[:inline_label] } else build_check_box diff --git a/test/inputs/boolean_input_test.rb b/test/inputs/boolean_input_test.rb index 4f6c4601..56085261 100644 --- a/test/inputs/boolean_input_test.rb +++ b/test/inputs/boolean_input_test.rb @@ -29,6 +29,13 @@ class BooleanInputTest < ActionView::TestCase end end + test 'input boolean with nested allows :inline_label' do + swap SimpleForm, :boolean_style => :nested do + with_input_for @user, :active, :boolean, :label => false, :inline_label => 'I am so inline.' + assert_select 'label.checkbox', :text => 'I am so inline.' + end + end + test 'input boolean with nested generates a manual hidden field for checkbox outside the label, to recreate Rails functionality with valid html5' do swap SimpleForm, :boolean_style => :nested do with_input_for @user, :active, :boolean @@ -98,4 +105,6 @@ class BooleanInputTest < ActionView::TestCase end end end + + end