【问题标题】:Multiple row text input with simple_form使用 simple_form 的多行文本输入
【发布时间】:2015-10-25 20:04:16
【问题描述】:

我有这个表格:

<%= simple_form_for @article do |m| %>
  <%= m.simple_fields_for :article_comment do |p| %>

    <%= p.error_notification %>

    <%= p.input :article_id, as: :hidden, input_html: {value: @article.id} %>
      <div class="form-inputs">
        <div class="row">
          <div class="col-md-2 col-md-offset-1">
            <%= p.label 'What do you think?', :class => 'indexsubtext' %>
          </div>
          <div class="col-md-9">
            <%= p.input :comment, label: false, autofocus: true, :input_html => {:style=> 'width: 100%', :rows => 5, class: 'response-project'} %>
          </div>

我想让输入框显示5行,但它只显示1。如何强制它提供5?

【问题讨论】:

    标签: ruby-on-rails simple-form


    【解决方案1】:

    默认情况下,simple_form 将根据您数据库中的类型选择元素。如果comment 是string 类型(而不是text),它将使用input 字段,该字段没有rows 属性。

    尝试添加as: :text 选项。这将强制元素为textarea:

    <%= p.input :comment, label: false, as: :text, autofocus: true, :input_html => {:style => 'width: 100%', :rows => 5, class: 'response-project'} %>
    

    这可能会像解决 this guy 一样解决您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-18
      • 1970-01-01
      • 2014-01-02
      • 2011-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多