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

refresh() does not take allowHTML into account #1220

Open
yubbink opened this issue Oct 11, 2024 · 0 comments
Open

refresh() does not take allowHTML into account #1220

yubbink opened this issue Oct 11, 2024 · 0 comments
Labels

Comments

@yubbink
Copy link

yubbink commented Oct 11, 2024

Describe the bug
The option allowHTML when creating a choice element allows label to have html input instead of just text. When you call .refresh() on the created choice element after that, it does not render the text inside label as html, but as normal text. Causing html tags to be displayed.

To Reproduce

<!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>
    <button onclick="window.choiceElement.refresh()">Click to refresh</button>
</div>
<script>
    window.choiceElement = new Choices(document.querySelector('#select'), {
        allowHTML: true,
    });

    window.choiceElement.setChoices([
        {
            value: '1',
            label: '<div>Text inside html tag</div>',
            selected: true
        }
    ], 'value', 'label', true)
</script>
</body>

click the button to call the refresh function and you'll see the selected element changing and showing the html tags

Expected behavior
You'd expect the html to render instead of plain text

Choices version and bundle
Found this bug in 10.2.0 under different circumstances, but as the example shows it is a problem in 11.0.2. Simple example with 10.2.0 version works, so I'm trying to find the underlaying cause for the same issue I'm facing there.

@yubbink yubbink added the bug label Oct 11, 2024
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

1 participant