Replies: 2 comments 1 reply
-
Do not remove the element, instead hide it: htmx.addClass(htmx.find('#error'), 'hideMeClass'); |
Beta Was this translation helpful? Give feedback.
-
Inline event handlers, not only advised against by the MDN doc (I mean the title is litterally It seems there are workarounds to reproduce that mechanism, but if you're looking for "the clean way", it'd be with an event listener, using the options.once parameter, such as elt.addEventListener("keydown", function() {
htmx.remove(htmx.find('#error-${id}'));
htmx.removeClass(htmx.find('#label-${id}'), 'text-red-500');
}, { once: true }) |
Beta Was this translation helpful? Give feedback.
-
I'm trying to figure out whats the best way to remove some nodes / css classes when a user starts to type on an input.
My use case is when a form is submitted, I return some html that renders in-line errors. However, I want those errors to go away as soon as the user starts typing. Here is an example (I'm using JSX, sorry!):
However, this works fine but after the first call this throws an error as the element no longer exist. Whats the best approach for achieving this?
Would be nice to have an
hx-on:keydown:once
Beta Was this translation helpful? Give feedback.
All reactions