首页 > 解决方案 > 有没有办法将占位符更改为简单形式的 as: :select 选项?

问题描述

从 simple_form_for 选择选项,我得到一个占位符,上面写着“选择一些选项”。我正在尝试对此进行自定义,但似乎找不到这样做的方法。占位符选项不起作用也不提示选项 在此处输入图像描述

这是我的代码

<%= f.input :tagging_ids, placeholder: "test", label: false, as: :select, collection: Tag.order(:name), input_html: {multiple: true} %>

我尝试将值替换为“选择一些选项”以外的其他值,但这仍然不起作用!我在这里想念什么

谢谢

标签: ruby-on-railsbootstrap-4ruby-on-rails-5simple-form

解决方案


尝试数据占位符

<%= 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


推荐阅读