gpt4 book ai didi

ruby-on-rails - 如何为 simple_form 自定义 rich_text_area 中的行数?

转载 作者:行者123 更新时间:2023-12-05 08:50:36 30 4
gpt4 key购买 nike

我正在使用 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..." %>

生成此 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>

看起来像这样:

simple-form-rich-text-area

请注意,我还尝试了 input_html: 的各种迭代,包括但不限于:

<%= ... input_html: { 'rows': '10' } ... %>

<%= ... input_html: { rows: "10" } ... %>

一切都无济于事。

我如何让它工作?

最佳答案

看起来 rich_text_area 只接受 :class 选项,所以 :input_html 在这里什么都不做。但是因为高度是由 CSS 决定的,我们可以通过覆盖 trix-editor 默认的 min-height CSS 来实现你想要的。

app/assets/stylesheets/actiontext.scss

trix-editor {
&.customized-min-height {
min-height: 15em;
}
}

在你的 View 文件中

f.rich_text_area :body, class: "form-control customized-min-height"

关于ruby-on-rails - 如何为 simple_form 自定义 rich_text_area 中的行数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61495382/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com