Add attribute for to label in collection extension
This commit is contained in:
parent
18c3cecedc
commit
958bcf4a32
|
@ -15,7 +15,19 @@ module SimpleForm
|
|||
|
||||
rendered_item = yield item, value, text, default_html_options.merge(additional_html_options)
|
||||
|
||||
item_wrapper_tag ? @template_object.content_tag(item_wrapper_tag, rendered_item, class: item_wrapper_class) : rendered_item
|
||||
if item_wrapper_tag
|
||||
options = { class: item_wrapper_class }
|
||||
|
||||
if item_wrapper_tag.to_s == 'label'
|
||||
label_options = {}
|
||||
add_default_name_and_id_for_value(text, label_options)
|
||||
options['for'] = label_options['id']
|
||||
end
|
||||
|
||||
@template_object.content_tag(item_wrapper_tag, rendered_item, options)
|
||||
else
|
||||
rendered_item
|
||||
end
|
||||
end.join.html_safe
|
||||
end
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
||||
assert_select 'input[type=radio][value=Jose]'
|
||||
assert_select 'input[type=radio][value=Carlos]'
|
||||
assert_select 'label.collection_radio_buttons', 'Jose'
|
||||
assert_select 'label.collection_radio_buttons', 'Carlos'
|
||||
assert_select 'label.collection_radio_buttons[for=user_name_jose]', 'Jose'
|
||||
assert_select 'label.collection_radio_buttons[for=user_name_carlos]', 'Carlos'
|
||||
end
|
||||
|
||||
test 'input should do automatic collection translation for radio types using defaults key' do
|
||||
|
@ -59,8 +59,8 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
||||
assert_select 'input[type=radio][value=male]'
|
||||
assert_select 'input[type=radio][value=female]'
|
||||
assert_select 'label.collection_radio_buttons', 'Male'
|
||||
assert_select 'label.collection_radio_buttons', 'Female'
|
||||
assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
|
||||
assert_select 'label.collection_radio_buttons[for=user_gender_female]', 'Female'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -71,8 +71,8 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
||||
assert_select 'input[type=radio][value=male]'
|
||||
assert_select 'input[type=radio][value=female]'
|
||||
assert_select 'label.collection_radio_buttons', 'Male'
|
||||
assert_select 'label.collection_radio_buttons', 'Female'
|
||||
assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
|
||||
assert_select 'label.collection_radio_buttons[for=user_gender_female]', 'Female'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue