I've adjusted the searchResultLimit
option to 10
in my code, but only 4 results are displayed.
Here is my code:
<select name="category_id" id="category" class="form-control choices-single js-choice" data-live-search="true" onchange="this.form.submit()">
<option>Rechercher une circonscription ...</option>
@foreach ($categories as $category)
<option value="{{ $category->id }}" {{ $categoryId == $category->id ? 'selected' : '' }}>
{{ $category->name }}
</option>
@endforeach
</select>
<script>
new Choices(document.querySelector(".js-choice"));
</script>
<script>
// Pass single element
const element = document.querySelector('.js-choice');
const choices = new Choices(element);
// Pass reference
const choices = new Choices('[data-trigger]');
const choices = new Choices('.js-choice');
// Pass jQuery element
const choices = new Choices($('.js-choice')[0]);
// Passing options (with default options)
const choices = new Choices(element, {
silent: false,
items: [],
choices: [],
renderChoiceLimit: -1,
maxItemCount: -1,
addItems: true,
addItemFilter: null,
removeItems: true,
removeItemButton: false,
editItems: false,
allowHTML: true,
duplicateItemsAllowed: true,
delimiter: ',',
paste: true,
searchEnabled: true,
searchChoices: true,
searchFloor: 1,
searchResultLimit: 10, // SEARCH RESULTS LIMIT SET TO 10
searchFields: ['label', 'value'],
position: 'auto',
resetScrollPosition: true,
shouldSort: true,
shouldSortItems: false,
sorter: () => {...},
placeholder: true,
placeholderValue: null,
searchPlaceholderValue: null,
prependValue: null,
appendValue: null,
renderSelectedChoices: 'auto',
loadingText: 'Loading...',
noResultsText: 'No results found',
noChoicesText: 'No choices to choose from',
itemSelectText: 'Press to select',
uniqueItemText: 'Only unique values can be added',
customAddItemText: 'Only values matching specific conditions can be added',
addItemText: (value) => {
return `Press Enter to add <b>"${value}"</b>`;
},
maxItemText: (maxItemCount) => {
return `Only ${maxItemCount} values can be added`;
},
valueComparer: (value1, value2) => {
return value1 === value2;
},
classNames: {
containerOuter: 'choices',
containerInner: 'choices__inner',
input: 'choices__input',
inputCloned: 'choices__input--cloned',
list: 'choices__list',
listItems: 'choices__list--multiple',
listSingle: 'choices__list--single',
listDropdown: 'choices__list--dropdown',
item: 'choices__item',
itemSelectable: 'choices__item--selectable',
itemDisabled: 'choices__item--disabled',
itemChoice: 'choices__item--choice',
placeholder: 'choices__placeholder',
group: 'choices__group',
groupHeading: 'choices__heading',
button: 'choices__button',
activeState: 'is-active',
focusState: 'is-focused',
openState: 'is-open',
disabledState: 'is-disabled',
highlightedState: 'is-highlighted',
selectedState: 'is-selected',
flippedState: 'is-flipped',
loadingState: 'is-loading',
noResults: 'has-no-results',
noChoices: 'has-no-choices'
},
// Choices uses the great Fuse library for searching. You
// can find more options here: https://fusejs.io/api/options.html
fuseOptions: {
includeScore: true
},
labelId: '',
callbackOnInit: null,
callbackOnCreateTemplates: null
});
</script>
new Choices(...)
calls, at least five of which appear to be for the same target element ...? (My guess would be, that this probably doesn't get overwritten, when the library realizes you have already initialized this for an element ... so it would apply the default options with your first initialization already, and ignores further attempts ...?)new Choices
will set the options and calling it again does not update the options. In your "answer"/edit you still callnew Choices
twice. Remove the first one, it's not needed, and you code will work fine. Here's a basic fiddle demonstrating searchResultLimit working fine: jsfiddle.net/759jo4e1