diff --git a/lib/simple_form/inputs/boolean_input.rb b/lib/simple_form/inputs/boolean_input.rb index 62a7839f..de37f90e 100644 --- a/lib/simple_form/inputs/boolean_input.rb +++ b/lib/simple_form/inputs/boolean_input.rb @@ -3,9 +3,12 @@ module SimpleForm class BooleanInput < Base def input if nested_boolean_style? + # If the inline_label option is a set to true then use the label_text as the inline_label + # otherwise use the specified object as the inline label (could be nil). + inline_label = options[:inline_label].eql?(true) ? label_text : options[:inline_label] build_hidden_field_for_checkbox + template.label_tag(nil, :class => "checkbox") { - build_check_box_without_hidden_field + options[:inline_label] + build_check_box_without_hidden_field + inline_label } else build_check_box diff --git a/test/inputs/boolean_input_test.rb b/test/inputs/boolean_input_test.rb index 8cd49817..287f7e6a 100644 --- a/test/inputs/boolean_input_test.rb +++ b/test/inputs/boolean_input_test.rb @@ -36,6 +36,13 @@ class BooleanInputTest < ActionView::TestCase end end + test 'input boolean with nested style creates an inline label using the default label text when inline_label option set to true' do + swap SimpleForm, :boolean_style => :nested do + with_input_for @user, :active, :boolean, :label => false, :inline_label => true + assert_select 'label.checkbox', :text => 'Active' + 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