如何为集合字段设置占位符文本
How to set placeholder text for collection field
我希望占位符字段显示 "Click to select" 但默认占位符仍显示 "Select Some Options"
<%= f.input :tag_ids, as: :select, collection: Tag.order(:name), label_method: :name, input_html: {multiple: true}, label: "Select Category:", placeholder: "Click to select", required: true %>
使用select的include_blank选项
select :object, :method, {:include_blank => ’-select-’}
有关详细信息,请参阅 the documentation
您可以使用prompt
选项,查看simple-form的文档示例
f.input :age, collection: 18..60, prompt: "Select your age", selected: 21
https://github.com/plataformatec/simple_form#collections
不需要设置as: :select
,select
是渲染集合时的默认值。
我希望占位符字段显示 "Click to select" 但默认占位符仍显示 "Select Some Options"
<%= f.input :tag_ids, as: :select, collection: Tag.order(:name), label_method: :name, input_html: {multiple: true}, label: "Select Category:", placeholder: "Click to select", required: true %>
使用select的include_blank选项
select :object, :method, {:include_blank => ’-select-’}
有关详细信息,请参阅 the documentation
您可以使用prompt
选项,查看simple-form的文档示例
f.input :age, collection: 18..60, prompt: "Select your age", selected: 21
https://github.com/plataformatec/simple_form#collections
不需要设置as: :select
,select
是渲染集合时的默认值。