【问题标题】:Simple form bootstrap design简单的表单引导设计
【发布时间】:2016-03-25 16:55:28
【问题描述】:

我如何制作简单的表格以使用

我当前的简单移动表单如下所示

<%= f.input :c_regular, :label => "Regular"%>
 <%= f.input :c_medium, :label => "Medium"%>
 <%= f.input :c_premium, :label => "Premium"%>
 <%= f.input :c_diesel, :label => "Diesel"%>
 <%= f.input :c_delivery, :label => "Delivery Charges"%>

我希望表单前面有一个 $,就像上图中的 @ 一样。

提前致谢。\

<div class="row">
        <%= simple_form_for @contact, url: supplier_contacts_path do |f| %>
        <%= f.input :first_name, label: "First Name" %>
        <%= f.input :last_name, label: "Last Name"%>
        <%= f.input :business_name, label: "Business Name" %>
        <%= f.input :phone_number, label: "Phone Number" %>
        <%= f.input :cell_number, label: "Mobile Number" %>
        <%= f.input :carrier, :label => "Mobile Carrier", :collection => mobile_carrier, :selected => "Tmobile"%>
        <%= f.input :street_address, label: "Street Address" %>
        <%= f.input :apt_suite, label: "Apt/Suite" %>
        <%= f.input :city, label: "City" %>
        <%= f.input :state, :label => "State", :collection => us_states, :selected => "New Jersey"%>
        <%= f.input :zip_code, :label => "Zip Code"%>
        <div class="input-group">
          <span class="input-group-addon">$</span>
          <%= f.input :c_regular, :label => "Regular", class:  "form-control" %>
        </div>
        <%= f.input :c_medium, :label => "Medium"%>
        <%= f.input :c_premium, :label => "Premium"%>
        <%= f.input :c_diesel, :label => "Diesel"%>
        <%= f.input :c_delivery, :label => "Delivery Charges"%>
        <%= f.button :submit, "Add Retailer", class: "btn btn-primary block full-width m-b"%>
        <%end%>
      </div>

【问题讨论】:

  • 你能用你在第一个响应中所做的更改来更新你上面的代码示例吗?我猜是嵌套错误,但需要查看您的代码示例才能给您修复
  • 在上面添加。谢谢

标签: ruby-on-rails ruby ruby-on-rails-4 simple-form


【解决方案1】:

如果您将 Bootstrap 3 用于您的 form_forform_tag,请尝试以下操作:

<div class="input-group">
  <span class="input-group-addon">$</span>
 <%= f.input :c_regular, :label => "Regular", class:  "form-control" %>
</div>

但是如果您使用的是simple_form_for,那么some issues 会带有一些引导组件,例如input_group

但幸运的是,也有一些解决方法。

第 1 步:

如果您在使用以下命令之前尚未完成,请为 simple_form 生成引导配置文件-

rails generate simple_form:install --bootstrap

这将在您的应用程序根目录的以下路径中创建一个配置文件 -

config/initializers/simple_form_bootstrap.rb

第 2 步:

在您的simple_form_bootstrap.rb 文件中包含以下附加包装器-

  config.wrappers :horizontal_input_group, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label, class: 'col-sm-3 control-label'

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

第三步: 修改你的simple_form_for如下:

<%= simple_form_for(@contact, url: supplier_contacts_path, html: { class: 'form-horizontal' }) do |f| %>
   <div class="form-inputs">
    <%= f.input :c_regular,wrapper: :horizontal_input_group do %>
     <span class="input-group-addon">$</span>
     <%= f.input_field :c_regular, :label => "Regular",class: "form-control" %>
    <% end %>
  </div>
<% end %>

【讨论】:

  • 现在看起来很奇怪哈哈。我为当前表单添加了上面的屏幕截图。
  • @suyesh 我已经编辑了 simple_form_for 的答案。仍然有一些 Bootstrap 组件在 simple_form_for 中不支持,如下所述:github.com/plataformatec/simple_form/wiki/…
猜你喜欢
  • 1970-01-01
  • 2019-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多