htmx icon indicating copy to clipboard operation
htmx copied to clipboard

element remains disabled in the history if hx-disabled-elt is used with HX-Push-Url header

Open apesternikov opened this issue 1 year ago • 6 comments

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.

apesternikov avatar Jan 22 '24 01:01 apesternikov

workaround:

addEventListener('htmx:beforeHistorySave', () =>{
    const b = document.getElementById('submit');
    b.removeAttribute('disabled');
})

apesternikov avatar Jan 22 '24 01:01 apesternikov

Can confirm this behavior.

blackfyre avatar Mar 08 '24 04:03 blackfyre

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");
  });
});

jackielii avatar May 16 '24 09:05 jackielii

I had to completely disable caching workaround this bug:

htmx.config.historyCacheSize = 0

And it seems to me this is somehow related to #2587.

renannprado avatar Jul 21 '24 12:07 renannprado