https://htmx.org logo
Join Discord
Powered by
# htmx-general
  • m

    mysterious-toddler-20573

    10/20/2020, 10:51 PM
    We should probably wait until after the swap to execute the code
  • m

    mysterious-toddler-20573

    10/20/2020, 10:52 PM
    Can you open an issue for that?
  • m

    mysterious-toddler-20573

    10/20/2020, 10:52 PM
    afterSettle is the best work around for now, but I will try to get that fixed this week
  • m

    mysterious-toddler-20573

    10/20/2020, 10:53 PM
    @User good point, we should defer to the
    defaultSwapStyle
  • m

    mysterious-toddler-20573

    10/20/2020, 10:53 PM
    would you like to do a fix for that?
  • q

    quaint-accountant-21340

    10/20/2020, 10:54 PM
    @User... ah perfect I can open an issue. btw htmx is really nice. If we could keep the js and html together and build a bit fancier stuff where things like select2 could be wired up on swap then a lot of these fancier interactions would be easier to code and we could go back to our happy Django MVC world and avoid SPA stuff for more cases.
  • m

    most-jelly-15242

    10/20/2020, 10:55 PM
    @User Sure, I can try πŸ™‚
  • q

    quaint-accountant-21340

    10/20/2020, 11:02 PM
    @mysterious-toddler-20573 filed https://github.com/bigskysoftware/htmx/issues/213
  • q

    quaint-accountant-21340

    10/20/2020, 11:03 PM
    If you need additional info let me know.
  • m

    mysterious-toddler-20573

    10/20/2020, 11:09 PM
    @User nope, that's all I need. I can make a really simple example that captures the problem and I bet it's an easy fix
  • q

    quaint-accountant-21340

    10/20/2020, 11:10 PM
    Awesome, thanks!
  • m

    mysterious-toddler-20573

    10/21/2020, 2:03 PM
    @User I'm looking at the code it the script should be executing after the swap/settle. Do you mind sharing your code so I can see how it might be different?
  • m

    mysterious-toddler-20573

    10/21/2020, 2:03 PM
    @User PR looks good, but I noted a potential issue with it, and I'd like to add tests as well.
  • m

    mysterious-toddler-20573

    10/21/2020, 4:51 PM
    Sounds like @big-airline-13935 is giving his sprig talk! Hope it’s a banger Ben!
  • q

    quaint-accountant-21340

    10/21/2020, 5:25 PM
    @User Here's a minimal example... Main Page
    Copy code
    <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
    Copy code
    <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>
  • q

    quaint-accountant-21340

    10/21/2020, 5:26 PM
    @User btw, if you don't include
    type="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?
  • q

    quaint-accountant-21340

    10/21/2020, 5:28 PM
    ^^ the above examples gives this error:
    Copy code
    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)
        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)
  • q

    quaint-accountant-21340

    10/21/2020, 5:32 PM
    Happy to share other info if you need it. NB: the ht-get has a django url tag in it b/c that's what I had handy.
  • m

    mysterious-toddler-20573

    10/21/2020, 6:26 PM
    @User if you just put this:
    Copy code
    html
    <script type="text/javascript">
      $("#test").select2();
    </script>
  • m

    mysterious-toddler-20573

    10/21/2020, 6:26 PM
    in the code does it work?
  • m

    mysterious-toddler-20573

    10/21/2020, 6:27 PM
    Yeah, the
    type
    attributre is a known issue, fixed in
    dev
    right now
  • q

    quaint-accountant-21340

    10/21/2020, 6:29 PM
    Do you mean excluding the
    $(document).ready(function() {
    ?
  • q

    quaint-accountant-21340

    10/21/2020, 6:33 PM
    I get the same error without that.
  • q

    quaint-accountant-21340

    10/21/2020, 6:33 PM
    In playing around with it:
  • q

    quaint-accountant-21340

    10/21/2020, 6:34 PM
    The only way I can get it to work is if I have the main page listen on the settle event and do the init there.
  • m

    mysterious-toddler-20573

    10/21/2020, 6:35 PM
    Is there any sort of module system? It seems like jQuery isn't initialized,
  • m

    mysterious-toddler-20573

    10/21/2020, 6:36 PM
    I wish I could see what line of code this is:
    Copy code
    `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)
  • m

    mysterious-toddler-20573

    10/21/2020, 6:36 PM
    what is calling querySelectorAll()
  • m

    mysterious-toddler-20573

    10/21/2020, 6:36 PM
    Is that inside the
    .select2()
    ?
  • m

    mysterious-toddler-20573

    10/21/2020, 6:37 PM
    The code should be executing after the document has been updated
1...575859...1146Latest