htmx icon indicating copy to clipboard operation
htmx copied to clipboard

target input type text should set the value attribute

Open flibustenet opened this issue 3 years ago • 4 comments

It was this old issue, i believe it didn't change ? Should we use outerHTML only or is there a way to swap to value ?

https://github.com/bigskysoftware/intercooler-js/issues/229

flibustenet avatar Jun 04 '22 20:06 flibustenet

I'm guessing that outerHTML works for you and you are looking for a HTMX to always treat hx-swap="innerHTML" on inputelements asouterHTML`?

checketts avatar Jun 13 '22 01:06 checketts

outerHTML works, but it could be fine that innerHTML on an input box change the value of the input.

flibustenet avatar Jun 13 '22 05:06 flibustenet

I think this would be best as it follows the principle of least surprise.

As a work-around:

  document.addEventListener("htmx:beforeSwap", e => {
    if (e.detail.target.tagName === 'INPUT') {
      e.preventDefault();
      e.detail.target.value = e.detail.serverResponse;
    }
  });

stevarino avatar May 04 '24 06:05 stevarino