question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Qute: Provide a clean way to return multiple fragments in one response (Htmx OOB Swap)

See original GitHub issue

Description

HTMX allow to do Out of band swapping of content: https://htmx.org/attributes/hx-swap-oob/

This means that the response contains multiple fragments of the view to be updated.

Example: Kapture-2022-11-14-at-09 33 16

When you click on the note, you need to update both the editor and the list of note.

Implementation ideas

I currently use this as a workaround: oob.html

{#for i in items}
{i.raw}
{/for}
    public static native TemplateInstance oob(Uni<String>... items);
...
    @Path("/note/{id}")
    public TemplateInstance editNote(@PathParam("id") Long id) {
        final Note note = Note.findById(id);
        if(note == null) {
            notes(null);
            return null;
        }
        if (isHxRequest()) {
            return  Templates.oob(
                    Templates.notes$noteList(Note.listAllSortedByLastUpdated(), id).createUni(),
                    Templates.notes$noteForm(note).createUni()
                    );
        }
        return Templates.notes(Note.listAllSortedByLastUpdated(), id, note);
    }

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ia3andycommented, Nov 14, 2022

This seems like a very good solution, I’ll add it to the future Renarde HxController for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

multi-swap extension - </> htmx
This extension allows you to swap multiple elements marked with the id attribute from the HTML response. You can also choose for each...
Read more >
Specify multiple targets to swap #44 - bigskysoftware/htmx
I understand how the oob feature lets me return multiple containers ... such that it only returns fragments in response to an htmx...
Read more >
Can hx-select-oob update several targets? - Stack Overflow
If your goal is to return html content and copy the same content to multiple targets - you simply use class selector instead...
Read more >
Out-of-band swaps with HTMX - .NET Guide - JetBrains
HTMX can process responses before placing them into our target element. Therefore, we only need to add the hx-swap-oob attribute along with ...
Read more >
Django and HTMX #17 - Updating Other Content - YouTube
In this video, learn how to update non-target elements using two different HTMX mechanisms: 1. Out-of-band swaps : with the hx- swap -...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found