简单表单关联与默认输入有冲突class
Simple form association has conflict with default input class
我有一个简单的表格。一切都很好,直到我想添加一个关联表单。该协会本身运作良好,所以我将跳过它。保存数据有效。问题在于异常中输入 class 的控制。
<%= simple_form_for @fabmoment do |f| %>
<%= f.input_field :title %>
<%= f.label :title %>
<%= f.error :title %>
<%= f.input_field :description, rows: 7 %>
<%= f.label :description %>
<%= f.error :description %><br><br>
<%= f.association :machines, as: :check_boxes,
:label_method => lambda { |m| " #{m.name}" } %>
<% end %>
如您所见,我非常明确我把什么放在哪里,这是因为我的 CSS 库 (W3.CSS)。问题是在我的初始化程序中,我将 "w3-input"
的 class 作为输入的默认值。但这对我的关联复选框不起作用。目前我看到标签和输入复选框不是内联的。
如果 "w3-input"
class 不存在,就不会出现这种情况。但是我不能删除它,我只能深入到 item_wrapper_tag
和 item_wrapper_class
.
这让他非常恼火。昨天我已经为此忙了几个小时。
为什么我不能做这样的事情:
<%= f.association :machines, as: :check_boxes do |m| %>
<%= m.check_box :machine_id, class: 'w3-check' %>
<%= m.label :name, class: 'w3-validate' %>
<% end %>
原来有一个选项可以通过 input_html
和 label_html
将 html 属性传递给 simple_form 标签。
您可以从 Here 中找到所有选项
对于您的上述问题,您可以执行类似
的操作
<%= f.association :machines, as: :check_boxes, input_html:{class: 'w3-check'} ,label_html: {class: 'w3-validate'}%>
这将在所有机器复选框上添加 w3-check
class 并在这些复选框的所有标签上添加 w3-validate
然后您可以相应地设置样式
我有一个简单的表格。一切都很好,直到我想添加一个关联表单。该协会本身运作良好,所以我将跳过它。保存数据有效。问题在于异常中输入 class 的控制。
<%= simple_form_for @fabmoment do |f| %>
<%= f.input_field :title %>
<%= f.label :title %>
<%= f.error :title %>
<%= f.input_field :description, rows: 7 %>
<%= f.label :description %>
<%= f.error :description %><br><br>
<%= f.association :machines, as: :check_boxes,
:label_method => lambda { |m| " #{m.name}" } %>
<% end %>
如您所见,我非常明确我把什么放在哪里,这是因为我的 CSS 库 (W3.CSS)。问题是在我的初始化程序中,我将 "w3-input"
的 class 作为输入的默认值。但这对我的关联复选框不起作用。目前我看到标签和输入复选框不是内联的。
如果 "w3-input"
class 不存在,就不会出现这种情况。但是我不能删除它,我只能深入到 item_wrapper_tag
和 item_wrapper_class
.
这让他非常恼火。昨天我已经为此忙了几个小时。
为什么我不能做这样的事情:
<%= f.association :machines, as: :check_boxes do |m| %>
<%= m.check_box :machine_id, class: 'w3-check' %>
<%= m.label :name, class: 'w3-validate' %>
<% end %>
原来有一个选项可以通过 input_html
和 label_html
将 html 属性传递给 simple_form 标签。
您可以从 Here 中找到所有选项
对于您的上述问题,您可以执行类似
<%= f.association :machines, as: :check_boxes, input_html:{class: 'w3-check'} ,label_html: {class: 'w3-validate'}%>
这将在所有机器复选框上添加 w3-check
class 并在这些复选框的所有标签上添加 w3-validate
然后您可以相应地设置样式