From 8f800a72d08cea3460199a3dd90456dc1e970c54 Mon Sep 17 00:00:00 2001 From: Timur Vafin Date: Sat, 4 Feb 2012 01:58:06 +0400 Subject: [PATCH] Add extra "checkbox" class to label with nested style enabled using :label_input in wrapper config --- lib/simple_form/inputs/boolean_input.rb | 5 ++++- test/inputs/boolean_input_test.rb | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/simple_form/inputs/boolean_input.rb b/lib/simple_form/inputs/boolean_input.rb index 5f30e53e..7ada93f1 100644 --- a/lib/simple_form/inputs/boolean_input.rb +++ b/lib/simple_form/inputs/boolean_input.rb @@ -16,8 +16,11 @@ module SimpleForm if options[:label] == false input elsif nested_boolean_style? + html_options = label_html_options.dup + html_options[:class].push(:checkbox) + build_hidden_field_for_checkbox + - @builder.label(label_target, label_html_options) { + @builder.label(label_target, html_options) { build_check_box_without_hidden_field + label_text } else diff --git a/test/inputs/boolean_input_test.rb b/test/inputs/boolean_input_test.rb index 56bdaf8f..4f6c4601 100644 --- a/test/inputs/boolean_input_test.rb +++ b/test/inputs/boolean_input_test.rb @@ -88,4 +88,14 @@ class BooleanInputTest < ActionView::TestCase 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 + with_input_for @user, :active, :boolean + + assert_select 'input[type=hidden] + label.boolean.checkbox > input.boolean' + end + end + end end