【问题标题】:Rails - simple formRails - 简单的形式
【发布时间】:2013-12-12 11:46:32
【问题描述】:

我在我的 Rails 应用程序中使用 simple_form gem。当我使用这样的代码时

= f.input_field :name, label: false, placeholder: 'Name'
= f.input_field :price, label: false, placeholder: 'Price'
= f.input_field :description, label: false, placeholder: 'Description'
= f.input_field :image, label: false, placeholder: 'Image'

我得到 HTML 输入:

<input class="string required textform" id="item_name" label="false" maxlength="255" name="item[name]" placeholder="Имя" size="255" type="text">

如您所见,输入的大小现在是 255。其实已经绰绰有余了。如何指定输入的大小?

【问题讨论】:

    标签: ruby-on-rails simple-form


    【解决方案1】:

    以下来自 simple_form 文档here

    也可以将任何 html 属性直接传递给输入, 通过使用 :input_html 选项,例如:

    <%= simple_form_for @user do |f| %>
      <%= f.input :username, input_html: { class: 'special' } %>
      <%= f.input :password, input_html: { maxlength: 20 } %>
      <%= f.input :remember_me, input_html: { value: '1' } %>
      <%= f.button :submit %>
    <% end %>
    

    【讨论】:

      【解决方案2】:

      name 输入设置100 的大小:

      = f.input :name, label: false, placeholder: 'Name', input_html: { size: 100 }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-11-04
        • 1970-01-01
        • 2020-12-13
        • 1970-01-01
        • 2018-04-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多