ruby-on-rails - 有没有办法将占位符更改为简单形式的 as: :select 选项?
问题描述
从 simple_form_for 选择选项,我得到一个占位符,上面写着“选择一些选项”。我正在尝试对此进行自定义,但似乎找不到这样做的方法。占位符选项不起作用也不提示选项
这是我的代码
<%= f.input :tagging_ids, placeholder: "test", label: false, as: :select, collection: Tag.order(:name), input_html: {multiple: true} %>
我尝试将值替换为“选择一些选项”以外的其他值,但这仍然不起作用!我在这里想念什么
谢谢
解决方案
尝试数据占位符
<%= f.input :standards, label: 'Standards', as: :select, collection: Standard.order(:id).all.map{ |s| [s[:name], s[:id]] }, multiple: true, input_html: { class: 'form-select',
'data-placeholder'=>Standard.present? ? "Ex: #{Standard.first(3).pluck(:name).join(', ')}" : 'No Standards Present'
} %>
更多参考:https ://harvesthq.github.io/chosen/#default-text-support
推荐阅读
- ios - 如何像标题一样将单元格固定到 collectionView 的顶部?
- mysql - 循环并使用存储的 MySql 进行选择
- square - 在正方形中获取属于客户的订单列表
- jsf - 使用 Primefaces 在同一列中创建具有两个过滤器的自定义过滤器
- mysql - sql presto 查询以可交互方式连接 2 个表
- docker - Docker 镜像 dotnet-framework 4.7.2-sdk 缺少 SDK 文件
- vba - 比较两个工作簿并删除匹配的行
- python - 是否有任何带有 key 参数的 set() Python 实现?
- azure-data-lake - uSQL 超出最大请求长度
- ios - 在 Xcode 10 中测量 UI 元素之间的距离