gpt4 book ai didi

html - simple_form bootstrap form-horizo​​ntal initializer wrappers 未应用

转载 作者:行者123 更新时间:2023-11-28 16:58:55 28 4
gpt4 key购买 nike

所以我正在使用 bootstrap-sasssimple_form gem 并使用 --boostrap 运行安装程序,这意味着它生成了 config/initializers/ 目录中的>simple_form_bootstrap.rb

我正在尝试使用 Bootstrap 中的 form-horizo​​ntal 类,但这需要用 div 包装 inputcol-xx-xx.

我查看了前面提到的初始化程序并看到了这个 block :

 config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
b.optional :pattern
b.optional :min_max
b.optional :readonly
b.use :label, class: 'col-sm-3 control-label'

b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
ba.use :input, class: 'form-control'
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end

这似乎初始化器已经将正确的类应用到标签并将输入标签包装在一个 div 中。然而,这种情况并非如此。初始化程序是否有错误?

作为引用,这是表格:

<%= simple_form_for @article, remote: true, html: {class: "form-horizontal"} do |f| %>
<ul class="errors"></ul>
<%= f.input :author%>
<%= f.input :title%>
<%= f.button :submit, class: "btn btn-primary" %>
<% end %>

这是相应的 html:

<div class="form-group string optional article_author">
<label class="string optional control-label" for="article_author">...</label>
<input id="article_author" class="string optional form-control" type=".." name=".." value="..." style="..."></input>
</div>

所以看起来像类 form-control 一样添加了初始化程序中的一些内容,但没有添加其他内容。为什么?

最佳答案

因此,您需要在 form_for 标签中使用 wrapper: "form_horizo​​ntal" 应用包装器。这将使用该名称的所有初始值设定项。

关于html - simple_form bootstrap form-horizo​​ntal initializer wrappers 未应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31617394/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com