simple_form 中的自定义包装器:重复输入
Custom wrapper in simple_form: duplicated input
我在我的输入周围使用 simple_form gem in my Rails 5.2 application. Currently, I'm having a bit of a problem when using custom wrappers。
我的包装纸
config.wrappers :mini_input, tag: 'div', class: 'row responsive-label', error_class: 'error' do |b|
b.use :html5
b.wrapper tag: 'div', class: 'col-sm-12 col-md-3' do |c|
c.use :label_input
end
b.wrapper tag: 'div', class: 'col-sm-12 col-md-4' do |c|
c.use :input
end
end
我的表格
simple_form_for(@user) do |f|
...
<%= f.input :name, required: true, label: "Name", autofocus: true, wrapper: :mini_input %>
...
end
预期输出
<div class="row responsive-label">
<div class="col-sm-12 col-md-3">
<label ...>
</div>
<div class="col-sm-12 col-md-4">
<input ...>
</div>
</div>
...实际输出
<div class="row responsive-label">
<div class="col-sm-12 col-md-3">
<label ...>
<input ...> <!-- This input should not be here -->
</div>
<div class="col-sm-12 col-md-4">
<input ...>
</div>
</div>
我在想我的包装器配置中可能有错误,我现在找不到它。
正如我的一个朋友 in a tweet 指出的那样,解决方案是在包装器配置中使用 label
而不是 label_input
。
config.wrappers :mini_input, tag: 'div', class: 'row responsive-label', error_class: 'error' do |b|
b.use :html5
b.wrapper tag: 'div', class: 'col-sm-12 col-md-3' do |c|
# c.use :label_input Wrong
c.use :label
end
b.wrapper tag: 'div', class: 'col-sm-12 col-md-4' do |c|
c.use :input
end
end
我在我的输入周围使用 simple_form gem in my Rails 5.2 application. Currently, I'm having a bit of a problem when using custom wrappers。
我的包装纸
config.wrappers :mini_input, tag: 'div', class: 'row responsive-label', error_class: 'error' do |b|
b.use :html5
b.wrapper tag: 'div', class: 'col-sm-12 col-md-3' do |c|
c.use :label_input
end
b.wrapper tag: 'div', class: 'col-sm-12 col-md-4' do |c|
c.use :input
end
end
我的表格
simple_form_for(@user) do |f|
...
<%= f.input :name, required: true, label: "Name", autofocus: true, wrapper: :mini_input %>
...
end
预期输出
<div class="row responsive-label">
<div class="col-sm-12 col-md-3">
<label ...>
</div>
<div class="col-sm-12 col-md-4">
<input ...>
</div>
</div>
...实际输出
<div class="row responsive-label">
<div class="col-sm-12 col-md-3">
<label ...>
<input ...> <!-- This input should not be here -->
</div>
<div class="col-sm-12 col-md-4">
<input ...>
</div>
</div>
我在想我的包装器配置中可能有错误,我现在找不到它。
正如我的一个朋友 in a tweet 指出的那样,解决方案是在包装器配置中使用 label
而不是 label_input
。
config.wrappers :mini_input, tag: 'div', class: 'row responsive-label', error_class: 'error' do |b|
b.use :html5
b.wrapper tag: 'div', class: 'col-sm-12 col-md-3' do |c|
# c.use :label_input Wrong
c.use :label
end
b.wrapper tag: 'div', class: 'col-sm-12 col-md-4' do |c|
c.use :input
end
end