【问题标题】:Simple_form adding class to formSimple_form 将类添加到表单
【发布时间】:2012-12-16 16:22:06
【问题描述】:

我在我的 Rails 应用程序中使用 simple_form,我尝试将 form-horizontal 类添加到我的表单中。

<form accept-charset="UTF-8" action="/account/orders" class="simple_form new_order" data-validate="true" enctype="multipart/form-data" id="new_order" method="post" novalidate="novalidate">

当我使用html: { class: "form-horizontal" } 时,它会将class="simple_form new_order" 更改为class="simple_form form-horizontal"

我应该怎么做才能保持new_order 上课?

【问题讨论】:

    标签: ruby-on-rails simple-form


    【解决方案1】:

    它像这样对我有用

    = simple_form_for @model, html: { class: "form-horizontal"} do |f|
      ...
    

    编译成

    <form accept-charset="UTF-8" action="/numbers" class="simple_form form-horizontal" id="new_number" method="post">
    

    【讨论】:

    • 我觉得值得一提的是,这个问题是在 2012 年 12 月提出的。根据版本历史,rubygems.org/gems/simple_form/versions,Simple Form 3 尚未发布。在 Simple Form 2 中,这个答案是不正确的。
    【解决方案2】:

    我是intended behaviour

    所以如果你想改变它,你应该在 this file 中修改 simple_form_css_class 方法。

    【讨论】:

      【解决方案3】:

      这对我有用 config.form_class = 'form-horizontal' 并保留 new_model 类

      【讨论】:

      • 这样做的明显缺点是现在每个表单都有这个类,这通常不是你想要的。
      猜你喜欢
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多