我们希望使用simple_form对大多数收音机应用第一个单选按钮包装器。我们已经在simple_form配置中这样做了。
config.wrapper_mappings = {
radio_buttons: :wrapped_radio_buttons
}头等舱:
config.wrappers(
:wrapped_radio_buttons,
class: "field-unit radio-buttons",
error_class: "field-with-errors"
) do |b|
b.use :error, wrap_with: { tag: "span", class: "field-error" }
b.use :label_input
end我们想将第二个无线电包装器应用于其他一些收音机:
config.wrappers(
:wrapped_radio_blocks,
class: "field-unit radio-buttons radio-block-group",
error_class: "field-with-errors"
) do |b|
b.use :label
b.use :error, wrap_with: { tag: "span", class: "field-error" }
b.wrapper tag: "div", class: "radio-blocks" do |ba|
ba.use :input
end
end我们尝试为第二个选项添加一个配置包装映射,但似乎每个html输入类型只能应用一个包装器。如何将第二个包装器应用于某些收音机?
以下是我们的html:
<%= f.input(
:fake_input,
as: :radio_buttons,
collection: t(
[
:radio_option_one,
:radio_option_two,
:radio_option_three,
:radio_option_four,
:radio_option_five,
],
scope: "fake_scope",
)
) %>对于第二个包装器类型,我们希望用不同的行替换该as: :radio_buttons。
发布于 2015-10-28 20:14:32
在使用班级解决方案而不是创建一个全新的simple_form自定义包装器后不久,我们就解决了这个问题。
<%= f.input(
:regular_radio_example,
as: :radio_buttons,
collection: t(
[
:radio_option_one,
:radio_option_two,
:radio_option_three,
:radio_option_four,
:radio_option_five,
],
scope: "fake_scope",
),
) %>
<%= f.input(
:new_cool_radio_example,
as: :radio_buttons,
wrapper_html: { class: "radio-block-group" },
collection: t(
[
:radio_option_one,
:radio_option_two,
:radio_option_three,
:radio_option_four,
:radio_option_five,
],
scope: "fake_scope",
),
collection_wrapper_tag: "div",
collection_wrapper_class: "radio-blocks",
) %>https://stackoverflow.com/questions/33400564
复制相似问题