我想要显示一个使用占位符的多选框(没什么特别的)。我在列表中添加了一个空白项,这样就可以按预期显示占位符。
<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站点上最接近的示例使用了选项组(my list没有),并且似乎没有空白选项。我不记得在v3.5x中遇到过这个问题。除了占位符之外,我没有设置任何选项。我能做错什么呢?我怎样才能摆脱这个额外的空白选择?
发布于 2016-02-10 18:25:47
你有没有碰巧在用Formtastic?我在使用Formtastic时遇到了这个问题。如果不是,也许这可以帮助你找到正确的方向。我必须将:include_blank => 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 => false.
可能是类似于这个的东西?
https://stackoverflow.com/questions/32674729
复制相似问题