Skip to content

Commit

Permalink
If inline_label opt is true use default label text
Browse files Browse the repository at this point in the history
Have the inline label text be set to the default
label text if the inline_label config is true.
  • Loading branch information
gmanley committed Apr 30, 2012
1 parent d43bbe9 commit 0c017e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/simple_form/inputs/boolean_input.rb
Expand Up @@ -3,9 +3,12 @@ module Inputs
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
Expand Down
7 changes: 7 additions & 0 deletions test/inputs/boolean_input_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 0c017e9

Please sign in to comment.