| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="UTF-8"> |
| 5 | <title>Aborting Request Event Test</title> |
| 6 | </head> |
| 7 | <body style="padding: 20px; font-family: sans-serif;"> |
| 8 | <h1>Aborting Request Event Tests</h1> |
| 9 | <p>Aborting a request during an HTMX event should not prevent future events from firing.</p> |
| 10 | <label for="block">Block Request?</label> |
| 11 | <input id="block" type="checkbox" checked> |
| 12 | <br><br> |
| 13 | <button hx-get="https://httpbin.org/html" |
| 14 | hx-target="#target"> |
| 15 | Send Request |
| 16 | </button> |
| 17 | <br><br> |
| 18 | <h3>Event Messages:</h3> |
| 19 | <div id="target"></div> |
| 20 | <script src="../../src/htmx.js"></script> |
| 21 | <script> |
| 22 | var btn = document.querySelector('button'); |
| 23 | var checkbox = document.querySelector('input'); |
| 24 | var target = document.querySelector('#target'); |
| 25 | |
| 26 | btn.addEventListener('htmx:beforeRequest', function(e) { |
| 27 | var messages = target.innerHTML; |
| 28 | target.innerHTML = messages + "<p>Another Message!</p>"; |
| 29 | |
| 30 | if (checkbox.checked) { |
| 31 | e.detail.xhr.abort(); |
| 32 | } |
| 33 | }); |
| 34 | </script> |
| 35 | </body> |
| 36 | </html> |