Merge pull request #1052 from megahbite/master
Add item label class option for collection inputs.
This commit is contained in:
commit
0eab4247be
|
@ -19,6 +19,7 @@ module SimpleForm
|
|||
label_options = {}
|
||||
add_default_name_and_id_for_value(value, label_options)
|
||||
label_options['for'] = label_options.delete('id')
|
||||
label_options['class'] = @options[:item_label_class]
|
||||
rendered_item = content_tag(:label, rendered_item, label_options)
|
||||
end
|
||||
|
||||
|
|
|
@ -245,6 +245,23 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'input check boxes with nested style renders item labels with specified class' do
|
||||
swap SimpleForm, boolean_style: :nested do
|
||||
with_input_for @user, :active, :check_boxes, item_label_class: "test"
|
||||
|
||||
assert_select 'span.checkbox > label.test > input'
|
||||
end
|
||||
end
|
||||
|
||||
test 'input check boxes with nested style and falsey input wrapper renders item labels with specified class' do
|
||||
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: false do
|
||||
with_input_for @user, :active, :check_boxes, item_label_class: "checkbox-inline"
|
||||
|
||||
assert_select 'label.checkbox-inline > input'
|
||||
assert_no_select 'span.checkbox'
|
||||
end
|
||||
end
|
||||
|
||||
test 'input check boxes wrapper class are not included when set to falsey' do
|
||||
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||
with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
|
||||
|
|
|
@ -368,6 +368,23 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'input radio with nested style renders item labels with specified class' do
|
||||
swap SimpleForm, boolean_style: :nested do
|
||||
with_input_for @user, :active, :radio_buttons, item_label_class: "test"
|
||||
|
||||
assert_select 'span.radio > label.test > input'
|
||||
end
|
||||
end
|
||||
|
||||
test 'input radio with nested style and falsey input wrapper renders item labels with specified class' do
|
||||
swap SimpleForm, boolean_style: :nested, item_wrapper_tag: false do
|
||||
with_input_for @user, :active, :radio_buttons, item_label_class: "radio-inline"
|
||||
|
||||
assert_select 'label.radio-inline > input'
|
||||
assert_no_select 'span.radio'
|
||||
end
|
||||
end
|
||||
|
||||
test 'input radio wrapper class are not included when set to falsey' do
|
||||
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
||||
|
|
Loading…
Reference in New Issue