From 0c017e9efb7d3c92efc95cc38668d61b8082bf13 Mon Sep 17 00:00:00 2001 From: Gray Manley Date: Mon, 30 Apr 2012 00:34:40 -0500 Subject: [PATCH] If inline_label opt is true use default label text Have the inline label text be set to the default label text if the inline_label config is true. --- lib/simple_form/inputs/boolean_input.rb | 5 ++++- test/inputs/boolean_input_test.rb | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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