如何为集合字段设置占位符文本

问题描述 投票:0回答:3

我希望占位符字段显示“单击以选择”,但默认占位符仍显示“选择某些选项”

 <%= 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 %>
ruby-on-rails simple-form
3个回答
2
投票

您可以使用

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
是渲染集合时的默认值。


0
投票

使用 select 的 include_blank 选项

select :object, :method, {:include_blank => ’-select-’}

请参阅文档了解更多信息


0
投票

由于某种原因,“提示”对我不起作用,但另一个可以尝试的是 data-placeholder (一个 input_html 选项)。

就这样:

<%= f.input :tag_ids, as: :select, collection: Tag.order(:name), label_method: :name, input_html: { multiple: true, 'data-placeholder' => 'Click to select' }, label: "Select Category:", required: true %>

© www.soinside.com 2019 - 2024. All rights reserved.