【问题标题】:Is there a way to change the place holder for simple form for as: :select option?有没有办法改变简单形式的占位符 as: :select 选项?
【发布时间】:2019-09-24 15:03:09
【问题描述】:

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

这是我的代码

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

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

谢谢

【问题讨论】:

  • 尝试使用prompt选项而不是placeholder
  • @chumakoff 试过不行...

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


【解决方案1】:

尝试数据占位符

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

【讨论】:

    猜你喜欢
    • 2016-10-08
    • 2021-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多