【问题标题】:Select2 4.0 multiple select box & placeholder displays blank item with selectionsSelect2 4.0 多选框和占位符显示带有选择的空白项目
【发布时间】:2015-09-20 01:00:48
【问题描述】:

我想显示一个使用占位符的多选框(没什么异常)。我在列表中添加了一个空白项,这样可以按预期显示占位符。

<select id="county_id" name="county_id" multiple="" tabindex="-1"     class="select2-hidden-accessible" aria-hidden="true">
<option value="" selected="selected"></option>
<option value="1">Adams</option>
<option value="2">Ashland</option>
<option value="3">Barron</option>

但是当我在列表中选择一个项目时,一个空白框(第一个空白选项)显示为第一个选择,就在我选择的项目之前。请注意下面的第一个列表项:

<span class="select2-selection select2-selection--multiple" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" tabindex="0">
<ul class="select2-selection__rendered">
<span class="select2-selection__clear">×</span>
<li class="select2-selection__choice" title=""><span class="select2-selection__choice__remove" role="presentation">×</span></li>
<li class="select2-selection__choice" title="Kenosha"><span class="select2-selection__choice__remove" role="presentation">×</span>Kenosha</li>

如果我没有在列表前添加空白选项,则占位符不起作用,默认情况下会选择第一个列表项。

select2 站点上最接近的示例使用选项组(我的列表没有),并且似乎没有空白选项。我不记得在 v3.5x 中遇到过这个问题。除了占位符,我没有设置任何选项。我可能做错了什么?我怎样才能摆脱这个多余的空白选择?

【问题讨论】:

    标签: jquery-select2-4


    【解决方案1】:

    您是否正在使用Formtastic?我在使用 Formtastic 时遇到了这个问题。如果没有,也许这可以帮助你走向正确的方向。我必须将:include_blank =&gt; false 传递到我的表单中才能删除空白元素。 docs:prompt – by default, all select inputs will have a blank option at the top of the list. You can add a prompt with the :prompt option, or disable the blank option with :include_blank =&gt; false. 也许是类似的东西?

    【讨论】:

      猜你喜欢
      • 2013-10-27
      • 2022-01-06
      • 2014-09-06
      • 1970-01-01
      • 1970-01-01
      • 2017-02-01
      • 1970-01-01
      • 2018-10-01
      • 2016-12-08
      相关资源
      最近更新 更多