htmx
htmx copied to clipboard
element remains disabled in the history if hx-disabled-elt is used with HX-Push-Url header
Using hx-disabled-elt to disable a form button with new URL pushed to the history using HX-Push-Url header causes button saved in history in disabled state. Then if I click "back" the button is disabled. Enabling the element back before pusing URL to the history would probably solve the problem.
workaround:
addEventListener('htmx:beforeHistorySave', () =>{
const b = document.getElementById('submit');
b.removeAttribute('disabled');
})
Can confirm this behavior.
I observe the same error. I got more general work around:
document.addEventListener("htmx:beforeHistorySave", () => {
const parent = document.querySelector("[hx-disabled-elt]");
if (!parent) return;
const childrenSelector = form.getAttribute("hx-disabled-elt");
const children = form.querySelectorAll(childrenSelector);
children.forEach((child) => {
child.removeAttribute("disabled");
});
});
I had to completely disable caching workaround this bug:
htmx.config.historyCacheSize = 0
And it seems to me this is somehow related to #2587.