htmxfasthtml

Cannot get hx-swap-oob to work with fasthtml


I'm trying to use hx-swap-oob with HTMX via fasthtml, but it doesn't seem to be working as expected. Here's my code:

Div(None, hx_swap_oob=True)

This renders as:

<div hx-swap-oob></div>

What am I doing wrong?


Solution

  • The issue is due to how True on kwargs is handled in fasthtml.

    hx_swap_oob=True is interpreted simply as "add the hx-swap-oob attribute without value."

    However, for the out of bound swap to work, a value of "true" is required.

    This can be achieved by setting hx_swap_oob="true", i.e. the solution is:

    Div(None, hx_swap_oob="true")
    

    which will render as

    <div hx-swap-oob="true"></div>