Reputation: 815
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
Upvotes: 0
Views: 1953
Reputation: 8858
Use the property minimumResultsForSearch
and set it as -1
.
$('#categoryList').select2({
placeholder: "CATEGORY",
minimumResultsForSearch: -1
});
The problem was listed here
Upvotes: 1
Reputation: 815
I ended up just editing the code of the select2.js file.
I changed this part (around line 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>'
);
To this:
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>'
);
I had to add a new placeholder in there as that got rid of the select2 placeholder. I then just added the placeholder text in with jquery.
There are also other answers HERE but they didn't work for me.
Upvotes: 1