htmx icon indicating copy to clipboard operation
htmx copied to clipboard

[+Extension] `hx-keep`, enables form and html content to persist across reloads.

Open AjaniBilby opened this issue 11 months ago • 1 comments

I've created a library to enable forms to be cached in localStorage to allow them to survive refreshes, accidental tab closures, etc - with the server being able to then clear the cache with http hx-keep-evict header when the data is successfully saved to the server.

banner

It also provides client side APIs to allow frontends like react to hook into it to store their state in a form for custom input elements.

HTML attribute prefix used: hx-keep* (with support for data- prefix) Respects hx-history="false"

AjaniBilby avatar Apr 26 '25 10:04 AjaniBilby

This does have some overlap with the behaviour of hx-preserve, however hx-keep has nothing to do with element state like video - it only considers the raw html or FormData.

AjaniBilby avatar Apr 26 '25 10:04 AjaniBilby