0

When you use the select2 'Multiple select boxes' option it gives you the option to enter text. I want to remove this functionality so the user can only click/touch the options available and the text cursor doesn't show up.

You can see the 'Multiple select boxes' option on their example page: https://select2.github.io/examples.html

My Code. (I'm using Laravel 5 blade templating)

  <div class="row searchBoxes show">
    {!! Form::open(['method' => 'GET', 'id' => 'searchForm', 'name' => 'searchForm', 'route' => 'articles_path']) !!}
        {!! Form::select('categoryList[]', $categories, null, ['class' => 'categorySelector', 'id' => 'categoryList', 'multiple']) !!}
        {!! Form::select('dayList[]', $days, null, ['class' => 'distanceSelector', 'id' => 'dayList', 'multiple']) !!}
    {!! Form::submit('MAKE ME HAPPY', array('id' => 'submitButton', 'class' => 'searchSubmit')) !!}
   {!! Form::close() !!}
</div>

    <script type="text/javascript">
    $('#categoryList').select2({
            placeholder: "CATEGORY",
            minimumResultsForSearch: -1
          });
      $('#dayList').select2({
        placeholder: "DAY",
      minimumResultsForSearch: -1
      });
    </script>

EDIT: I found the info about 'Hiding the search box'. I have tried switching minimumResultsForSearch to 'infinity' and it still didn't work. Here is my app: www.gethappy.co.nz

4

2 回答 2

1

使用该属性minimumResultsForSearch并将其设置为-1.

$('#categoryList').select2({
    placeholder: "CATEGORY",
    minimumResultsForSearch: -1
});

例子

问题已在此处列出

于 2016-01-29T01:10:39.463 回答
1

我最终只是编辑了 select2.js 文件的代码。

我改变了这部分(大约 1810 行)

  Search.prototype.render = function (decorated) {
    var $search = $(
      '<li class="select2-search select2-search--inline">' +
        '<input class="select2-search__field" type="search" tabindex="-1"' +
        ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
        ' spellcheck="false" role="textbox" aria-autocomplete="list" />' +
      '</li>'
    );

对此:

  Search.prototype.render = function (decorated) {
    var $search = $(
      '<li>' +
        '<input tabindex="-1"' +
        ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
        ' spellcheck="false" role="textbox" aria-autocomplete="list" style="display: none" />' +
        '<p class="placeHolderText"></p>' +
      '</li>'
    );

我不得不在那里添加一个新的占位符,因为它摆脱了 select2 占位符。然后我只是在 jquery 中添加了占位符文本。

这里还有其他答案,但它们对我不起作用。

于 2016-01-31T22:29:35.277 回答