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.
This commit is contained in:
Gray Manley 2012-04-30 00:34:40 -05:00
parent d43bbe9be7
commit 0c017e9efb
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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