0

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>
6
  • "but only 4 results are displayed" - and you're sure there are more results, with whatever your current search criteria were ...?
    – CBroe
    Commented Jul 3 at 10:46
  • Yes! I am sure there are more results than the ones displayed when typing.
    – Alex01
    Commented Jul 3 at 10:52
  • 1
    Why are there six 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 ...?)
    – CBroe
    Commented Jul 3 at 11:00
  • limit to 10 .. minimum - the limit would be the maximum results, not the minimum. "Minimum" makes no sense, eg if there's only 4, how can there be a minimum of 10?
    – fdomn-m
    Commented Jul 3 at 14:21
  • 1
    As noted above by @CBroe, calling new Choices will set the options and calling it again does not update the options. In your "answer"/edit you still call new 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
    – fdomn-m
    Commented Jul 3 at 14:30

1 Answer 1

0

I've reduced the new Choices(...) calls like below, but I still get 4 results and not more when typing.

<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>
    // Pass single element
    const element = document.querySelector('.js-choice');

    // 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, // DOES NOT WORK
        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>
2
  • This does not answer the question. Please edit your question to add updates based on comments.
    – fdomn-m
    Commented Jul 3 at 14:21
  • Updated. Your https://jsfiddle.net/759jo4e1 works fine.
    – Alex01
    Commented Jul 3 at 14:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.