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:
parent
d43bbe9be7
commit
0c017e9efb
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue