Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setChoices doesn't render choices on dropdown open #1203

Open
viliusvsx opened this issue Sep 13, 2024 · 1 comment
Open

setChoices doesn't render choices on dropdown open #1203

viliusvsx opened this issue Sep 13, 2024 · 1 comment
Assignees
Labels

Comments

@viliusvsx
Copy link

Describe the bug
When trying to set choices with setChoices() method, choices will not be shown when opening dropdown. I tried this with the 10.0.2 version, and that was not the case

To Reproduce
Just create any .html file and put the code I provide

<!doctype html>
<html>
<head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/choices.min.css"/>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/public/assets/scripts/choices.min.js"></script>
</head>
<body>
<div>
    <select id="select"></select>
</div>
<script>
    const select = new Choices(document.querySelector('#select'), {
        maxItemCount: -1,
        searchFloor: 0,
        renderChoiceLimit: -1,
        searchResultLimit: -1,
        searchEnabled: true,
    });

    select.setChoices([
        {
            value: '120',
            label: 'User Name',
            selected: true
        }
    ], 'value', 'label', true)
</script>
</body>

Expected behavior
I think, that when I set selected option by setChoices method, I except that when I open dropdown, I could see that option in list, without writing anything in search bar. I tried this with 10.0.2 version, and that was not the case. On dropdown open, I could see all choices that I set

Screenshots
I provided the html code, that you simply need to put in any html file

Choices version and bundle

  • Version: v11.0.2 choices.min.js

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome
  • Version: 128.0.6613.138
@viliusvsx viliusvsx added the bug label Sep 13, 2024
@Xon Xon self-assigned this Sep 18, 2024
@dfcalexandre
Copy link

The same is happening to me and it only seems to happen when a single option is available in the select.

Steps to reproduce:

  1. Create a select with a single option. If possible add a placeholder option so that it doesn't auto-select that same option to view results more clearly.
  2. Open the dropdown, the option will appear on the list.
  3. Select that option and re-open the dropdown. It will now show "No choices to choose from" and it won't show the selected option. If you have search enabled and you search for that option it will then show it together with the same message.
  4. Clear the selected option using the remove button, the dropdown will now show the option again as well as the "No choices to choose from" message

If I add a second selectable option to the select element everything works properly again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants