mysterious-toddler-20573
12/27/2021, 3:34 PMmysterious-toddler-20573
12/27/2021, 3:35 PMmysterious-toddler-20573
12/27/2021, 3:36 PMmysterious-toddler-20573
12/27/2021, 3:37 PMadamant-exabyte-92636
12/27/2021, 3:43 PMadamant-exabyte-92636
12/27/2021, 3:44 PMblue-gold-89534
12/27/2021, 3:44 PMblue-gold-89534
12/27/2021, 3:45 PMcalm-ice-23682
12/27/2021, 5:39 PMmysterious-toddler-20573
12/27/2021, 5:53 PMmammoth-orange-72182
12/27/2021, 6:17 PM<button type="button"
class="btn btn-sm btn-outline-secondary"
hx-trigger="click"
hx-swap="outerHTML"
hx-target="#account{{ account.id }}"
hx-indicator="#deleteindicator{{ account.id }}"
hx-confirm="Are you sure you wish to delete your account?"
hx-delete="{% url "google_cal_auth" account.id %}">
{% icon "trash" height="16" width="16" %}
Remove
</button>
<button id="deleteindicator{{ account.id }}"
class="htmx-indicator btn btn-sm btn-outline-secondary"
disabled
type="button">
<span class="spinner-border spinner-border-sm"
role="status"
aria-hidden="true"></span>
Removing...
</button>
<style>
.htmx-indicator{
display:none;
}
.htmx-request.htmx-indicator{
display:inline;
}
</style>gorgeous-ghost-95789
12/27/2021, 6:18 PMhtmx-indicator -- https://htmx.org/reference/#classesmammoth-orange-72182
12/27/2021, 6:19 PMmammoth-orange-72182
12/27/2021, 6:20 PMgorgeous-ghost-95789
12/27/2021, 6:20 PMgorgeous-ghost-95789
12/27/2021, 6:25 PMhx-request is applied to the element that makes a request. Since buttons can contain sub elements, you should be able to do some magic with CSS. Would something like this work?
html
<button ...>
<span class="requesting">my spinner</span>
<span class="regular">Remove</span>
</button>
<style>
button .regular {display:inline;}
button.htmx-request .regular {display:none;}
button .requesting {display:nond;}
button.htmx-request .requesting {display:inline;}
</style>gorgeous-ghost-95789
12/27/2021, 6:26 PMmammoth-orange-72182
12/27/2021, 6:31 PMhx-request being added to the element that makes a request.mammoth-orange-72182
12/27/2021, 6:32 PMhtmx-request, that is added to the element specified by hx-indicatorgorgeous-ghost-95789
12/27/2021, 6:57 PMmysterious-toddler-20573
12/27/2021, 7:10 PMhtmx-request class and hx-indicator. Can you add it to a parent element of the button (or point it to the button itself) to achieve this? If not, we can give you a bit of javascript or hyperscript to achieve what you want.gorgeous-ghost-95789
12/27/2021, 7:16 PMhtml
<span id="delete-01" class="delete-button">
<button
class="btn btn-sm btn-outline-secondary"
hx-trigger="click"
hx-swap="outerHTML"
hx-target="#account-01"
hx-indicator="#delete-01"
hx-confirm="Are you sure you wish to delete your account?"
hx-delete="/slow">
Remove
</button>
<button disabled class="btn btn-sm btn-outline-secondary">
<span class="spinner-border spinner-border-sm" role="status"></span>
Removing...
</button>
</span>
<style>
.delete-button button:not([disabled]) {
display:inline;
}
.delete-button button[disabled] {
display:none;
}
.delete-button.htmx-request button:not([disabled]) {
display:none;
}
.delete-button.htmx-request button[disabled] {
display:inline;
}
</style>gorgeous-ghost-95789
12/27/2021, 7:17 PMgorgeous-ghost-95789
12/27/2021, 7:23 PMhtml
<h2>Hyperscript Button</h2>
<button
class="hyperscript-button"
hx-delete=""
hx-prompt=""
script="on htmx:beforeRequest add [@disabled] to me">
<span class="regular">Remove</span>
<span class="if-disabled">Removing...</span>
</button>
<style>
.hyperscript-button .if-disabled {display:none;}
.hyperscript-button[disabled] .regular{display:none;}
.hyperscript-button[disabled] .if-disabled{display:inline;}
</style>refined-waiter-90422
12/27/2021, 7:25 PMmysterious-toddler-20573
12/27/2021, 7:26 PMgorgeous-airport-54386
12/27/2021, 7:27 PMuser
12/27/2021, 7:29 PMmysterious-toddler-20573
12/27/2021, 7:37 PMgorgeous-airport-54386
12/27/2021, 7:37 PM