【问题标题】:Rails 3: Changing input box lengthRails 3:更改输入框长度
【发布时间】:2012-08-17 05:12:49
【问题描述】:

使用带有 Twitter Bootstrap 和 Simple_form 的 Rails 3,我在更改此字段中输入框的长度时遇到问题:

<div class="input-prepend input-append">
   <%= f.input :price, :wrapper => :append do %>
      <span class="add-on">$</span>
      <%= f.input_field :price %>
      <span class="add-on">.00</span>
   <% end %>
</div>

其他人说要在 :price 变量之后添加:

:input_html => {:size => 15}

“do”循环似乎改变了规则,有什么建议吗?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 forms twitter-bootstrap simple-form


    【解决方案1】:

    试试

    :style => "width: 100px;"
    

    【讨论】:

      【解决方案2】:

      Twitter 引导程序为此提供了 css 类。根据您想要的大小,您可以添加类input-mininput-smallinput-largeso on。您还可以使用跨度类,例如span1span2

      <div class="input-prepend input-append">
         <%= f.input :price, :wrapper => :append do %>
            <span class="add-on">$</span>
            <%= f.input_field :price, :class => 'input-medium' %>
            <span class="add-on">.00</span>
         <% end %>
      </div>
      

      【讨论】:

        【解决方案3】:

        我正在使用f.input 表单在:class =&gt; 'form-horizontal' 表单中创建带有标签的控件,使用类属性或样式属性(直接或作为哈希,我尝试过的任何方式)对我不起作用,并且对生成的 HTML 的影响为零。

        这对我有用:

        <%= f.input :description, input_html: { class: 'span12' } %>
        

        这适用于 Bootstrap 列布局类(“span1”、“span2”等)、输入大小调整类(“input-large”、“input-xxlarge”等)或您想要的任何自定义类.诀窍是使用input_html 键。您也可以使用label_html 键来弄乱标签,但这可能会弄乱表单水平布局。

        看起来:input_html =&gt; {**:size** =&gt; 15} 中的 size 键被 SimpleForm 忽略了...当我厌倦了它并没有影响 HTML 输出。

        我在 SimpleForm 文档中找到了这个: https://github.com/plataformatec/simple_form#usage

        【讨论】:

        • 请注意,为了全面更改输入,您可以在表单中添加 defaults: { input_html: { class: 'default_class' } } 而不是添加每个元素,这可能会对您有所帮助,因为它对我有所帮助...跨度>
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-05-09
        • 2011-10-28
        • 2011-05-24
        • 1970-01-01
        • 2012-10-16
        • 2017-09-23
        • 2020-06-01
        相关资源
        最近更新 更多