UNPKG

536 BJavaScriptView Raw
1"use strict";
2
3// Disable Submit Button
4htmx.defineExtension('disable-element', {
5 onEvent: function (name, evt) {
6 let elt = evt.detail.elt;
7 let target = elt.getAttribute("hx-disable-element");
8 let targetElement = (target == "self") ? elt : document.querySelector(target);
9
10 if (name === "htmx:beforeRequest" && targetElement) {
11 targetElement.disabled = true;
12 } else if (name == "htmx:afterRequest" && targetElement) {
13 targetElement.disabled = false;
14 }
15 }
16});
\No newline at end of file