Skip to content

Preserving client side state, specifically details #1004

Answered by David-Guillot
yatesco asked this question in Q&A
Discussion options

You must be logged in to vote

Ah yes... In this case it's a bit trickier. I have one more idea for you, but I haven't tested it. It would be to combine hx-preserve and hx-swap-oob to:

  • Avoid replacing the <details>, in order to preserve its state
  • But replace its contents as if it was out-of-band target

On server side, you'd have to:

  • Wrap you details contents in some <div> which would hold the id that's required for hx-swap-oob
  • Put the details contents at the root of the HTML fragment returned in case of htmx request

I hope this is clear enough...

Replies: 5 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@yatesco
Comment options

Answer selected by yatesco
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants