Debian Codegraph @

www/static/test/manual/hx-redirect-indicator.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script>
5 window.fetch = function(url, options) {
6 return new Promise((resolve) => {
7 setTimeout(() => resolve({
8 ok: true,
9 status: 200,
10 headers: new Headers({'HX-Redirect': 'https://htmx.org'}),
11 text: () => Promise.resolve(''),
12 clone() { return this; }
13 }), 1500);
14 });
15 };
16 </script>
17 <script src="../../src/htmx.js"></script>
18 </head>
19 <body>
20 <h1>HX-Redirect indicator preservation</h1>
21 <p>
22 Click the button. The <code>.htmx-request</code> class and <code>disabled</code> state
23 should remain active during the 1.5s delay <em>and</em> after the response arrives
24 (while the page would normally be redirecting). They should <strong>not</strong> be
25 removed before navigation.
26 </p>
27
28 <button id="btn"
29 hx-post="/redirect"
30 hx-disabled-elt="#btn"
31 hx-indicator="#spinner">
32 Click me
33 </button>
34
35 <span id="spinner" class="htmx-indicator"> ⏳ loading...</span>
36
37 <p>
38 Button should stay <strong>disabled</strong> and spinner should stay
39 <strong>visible</strong> after the response — not flash back to normal.
40 </p>
41
42 <p>
43 <strong>keepIndicators override:</strong> set <code>ctx.keepIndicators = false</code>
44 via event to force cleanup even on redirect:
45 </p>
46
47 <button id="btn2"
48 hx-post="/redirect"
49 hx-disabled-elt="#btn2"
50 hx-indicator="#spinner2"
51 hx-on:htmx:finally:request="event.detail.ctx.keepIndicators = false">
52 Click me (indicators cleared on redirect)
53 </button>
54
55 <span id="spinner2" class="htmx-indicator"> ⏳ loading...</span>
56 </body>
57 </html>