Generate right for attribute for labels in collection inputs
It is wrong if namespace or index option is being used. Fixes #1161
This commit is contained in:
parent
812f1209bc
commit
106e775150
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
### bug fix
|
### bug fix
|
||||||
* Fix `full_error` when the attribute is an association. [@mvdamme](https://github.com/jorge-d)
|
* Fix `full_error` when the attribute is an association. [@mvdamme](https://github.com/jorge-d)
|
||||||
|
* Fix suppport to `:namespace` and `:index` options for nested check boxes and radio buttons when the attribute is an association.
|
||||||
|
|
||||||
## 3.1.0.rc2
|
## 3.1.0.rc2
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,9 @@ module SimpleForm
|
||||||
rendered_item = yield item, value, text, default_html_options.merge(additional_html_options)
|
rendered_item = yield item, value, text, default_html_options.merge(additional_html_options)
|
||||||
|
|
||||||
if @options.fetch(:boolean_style, SimpleForm.boolean_style) == :nested
|
if @options.fetch(:boolean_style, SimpleForm.boolean_style) == :nested
|
||||||
label_options = {}
|
label_options = default_html_options.slice(:index, :namespace)
|
||||||
add_default_name_and_id_for_value(value, label_options)
|
|
||||||
label_options['for'] = label_options.delete('id')
|
|
||||||
label_options['class'] = @options[:item_label_class]
|
label_options['class'] = @options[:item_label_class]
|
||||||
rendered_item = content_tag(:label, rendered_item, label_options)
|
rendered_item = @template_object.label(@object_name, sanitize_attribute_name(value), rendered_item, label_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
item_wrapper_tag ? @template_object.content_tag(item_wrapper_tag, rendered_item, class: item_wrapper_class) : rendered_item
|
item_wrapper_tag ? @template_object.content_tag(item_wrapper_tag, rendered_item, class: item_wrapper_class) : rendered_item
|
||||||
|
|
|
@ -278,4 +278,26 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
||||||
assert_select 'span.custom'
|
assert_select 'span.custom'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'input check boxes with nested style and namespace uses the right for attribute' do
|
||||||
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||||
|
with_concat_form_for @user, namespace: :foo do |f|
|
||||||
|
concat f.input :gender, as: :check_boxes, collection: [:male, :female]
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_select 'label[for=foo_user_gender_male]'
|
||||||
|
assert_select 'label[for=foo_user_gender_female]'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'input check boxes with nested style and index uses the right for attribute' do
|
||||||
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||||
|
with_concat_form_for @user, index: 1 do |f|
|
||||||
|
concat f.input :gender, as: :check_boxes, collection: [:male, :female]
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_select 'label[for=user_1_gender_male]'
|
||||||
|
assert_select 'label[for=user_1_gender_female]'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -393,7 +393,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'input check boxes custom wrapper class is included when include input wrapper class is falsey' do
|
test 'input radio custom wrapper class is included when include input wrapper class is falsey' do
|
||||||
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||||
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female], item_wrapper_class: 'custom'
|
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female], item_wrapper_class: 'custom'
|
||||||
|
|
||||||
|
@ -401,4 +401,26 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
||||||
assert_select 'span.custom'
|
assert_select 'span.custom'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'input radio with nested style and namespace uses the right for attribute' do
|
||||||
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||||
|
with_concat_form_for @user, namespace: :foo do |f|
|
||||||
|
concat f.input :gender, as: :radio_buttons, collection: [:male, :female]
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_select 'label[for=foo_user_gender_male]'
|
||||||
|
assert_select 'label[for=foo_user_gender_female]'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'input radio with nested style and index uses the right for attribute' do
|
||||||
|
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||||
|
with_concat_form_for @user, index: 1 do |f|
|
||||||
|
concat f.input :gender, as: :radio_buttons, collection: [:male, :female]
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_select 'label[for=user_1_gender_male]'
|
||||||
|
assert_select 'label[for=user_1_gender_female]'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue