mar*_*ion 2 ruby-on-rails simple-form trix ruby-on-rails-6 actiontext
我正在SimpleForm 5.0.2与 ActionText 一起使用。
我希望表单的主体字段为多行(比如 10 行),但我不知道如何让它工作。
这是我目前的尝试:
<%= f.rich_text_area :body, class: 'form-control', name: "article-text", input_html: { rows: 10 }, placeholder: "Enter your article body here..." %>
Run Code Online (Sandbox Code Playgroud)
这会生成以下 HTML:
<trix-editor class="form-control" input_html="{:rows=>10}" placeholder="Enter your article body here..." id="article_body" input="article_body_trix_input_article" data-direct-upload-url="http://localhost:3000/rails/active_storage/direct_uploads" data-blob-url-template="http://localhost:3000/rails/active_storage/blobs/:signed_id/:filename" contenteditable="" role="textbox" trix-id="1" toolbar="trix-toolbar-1"></trix-editor>
Run Code Online (Sandbox Code Playgroud)
看起来像这样:
请注意,我还尝试了各种迭代input_html:,包括但不限于:
<%= ... input_html: { 'rows': '10' } ... %>
<%= ... input_html: { rows: "10" } ... %>
Run Code Online (Sandbox Code Playgroud)
一切都无济于事。
我怎样才能让它发挥作用?
小智 9
它看起来像是rich_text_area唯一接受的:class选项,因此:input_html这里什么也不做。但是因为高度是由CSS决定的,所以我们可以通过覆盖trix-editor默认的最小高度CSS来实现你想要的。
在应用程序/资产/样式表/actiontext.scss
trix-editor {
&.customized-min-height {
min-height: 15em;
}
}
Run Code Online (Sandbox Code Playgroud)
在您的视图文件中
f.rich_text_area :body, class: "form-control customized-min-height"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2993 次 |
| 最近记录: |