mysterious-toddler-20573
10/20/2020, 10:51 PMmysterious-toddler-20573
10/20/2020, 10:52 PMmysterious-toddler-20573
10/20/2020, 10:52 PMmysterious-toddler-20573
10/20/2020, 10:53 PMdefaultSwapStyle
mysterious-toddler-20573
10/20/2020, 10:53 PMquaint-accountant-21340
10/20/2020, 10:54 PMmost-jelly-15242
10/20/2020, 10:55 PMquaint-accountant-21340
10/20/2020, 11:02 PMquaint-accountant-21340
10/20/2020, 11:03 PMmysterious-toddler-20573
10/20/2020, 11:09 PMquaint-accountant-21340
10/20/2020, 11:10 PMmysterious-toddler-20573
10/21/2020, 2:03 PMmysterious-toddler-20573
10/21/2020, 2:03 PMmysterious-toddler-20573
10/21/2020, 4:51 PMquaint-accountant-21340
10/21/2020, 5:25 PM<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>
<script src="https://unpkg.com/htmx.org@0.2.0"></script>
</head>
<body>
<h1>htmx test</h1>
<a href="#" hx-get="{% url 'htmx-select2-example-select2-fragment' %}">load select2</a>
</body>
</html>
Fragment with select2 and js code to init
<select id="test">
<option>foo</option>
</select>
<script type="text/javascript">
$(document).ready(function() {
console.log("about to init select2");
console.log($("#test"));
$("#test").select2();
});
</script>
quaint-accountant-21340
10/21/2020, 5:26 PMtype="text/javascript"
nothing happens. You don't get an error but you don't get a select2 either. I'm guessing the js isn't evaled in that case. Perhaps including the type is good form but might be worth mentioning in the docs?quaint-accountant-21340
10/21/2020, 5:28 PMhtmx.org@0.2.0:1 TypeError: Cannot read property 'querySelectorAll' of undefined
at J (htmx.org@0.2.0:1)
at $ (htmx.org@0.2.0:1)
at eval (eval at Re (htmx.org@0.2.0:1), <anonymous>:2:5)
at Re (htmx.org@0.2.0:1)
at He (htmx.org@0.2.0:1)
at htmx.org@0.2.0:1
at htmx.org@0.2.0:1
at R (htmx.org@0.2.0:1)
at i (htmx.org@0.2.0:1)
quaint-accountant-21340
10/21/2020, 5:32 PMmysterious-toddler-20573
10/21/2020, 6:26 PMhtml
<script type="text/javascript">
$("#test").select2();
</script>
mysterious-toddler-20573
10/21/2020, 6:26 PMmysterious-toddler-20573
10/21/2020, 6:27 PMtype
attributre is a known issue, fixed in dev
right nowquaint-accountant-21340
10/21/2020, 6:29 PM$(document).ready(function() {
?quaint-accountant-21340
10/21/2020, 6:33 PMquaint-accountant-21340
10/21/2020, 6:33 PMquaint-accountant-21340
10/21/2020, 6:34 PMmysterious-toddler-20573
10/21/2020, 6:35 PMmysterious-toddler-20573
10/21/2020, 6:36 PM`htmx.org@0.2.0:1 TypeError: Cannot read property 'querySelectorAll' of undefined
at J (htmx.org@0.2.0:1)
at $ (htmx.org@0.2.0:1)
mysterious-toddler-20573
10/21/2020, 6:36 PMmysterious-toddler-20573
10/21/2020, 6:36 PM.select2()
?mysterious-toddler-20573
10/21/2020, 6:37 PM