mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-02 07:21:05 +00:00
docs: fix this
binding in onClick .then
handler with arrow function (#2373)
docs: fix `this` binding in onClick .then handler with arrow fn Update the `.then()` handler in the `onClick` attribute to use an arrow function instead of a traditional `function(arg)` expression. This fixes the `this` binding within the lexical scope, ensuring that `this` is bound to the `button` instead of the `window` and resolving the issue. Fixes/Closes issue #2257
This commit is contained in:
parent
f9591c9790
commit
b176784f31
@ -17,7 +17,7 @@ the [`htmx:confirm`](@/events.md#htmx:confirm) event.
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<button hx-get="/confirmed"
|
||||
hx-trigger='confirmed'
|
||||
onClick="Swal.fire({title: 'Confirm', text:'Do you want to continue?'}).then(function(result){
|
||||
onClick="Swal.fire({title: 'Confirm', text:'Do you want to continue?'}).then((result)=>{
|
||||
if(result.isConfirmed){
|
||||
htmx.trigger(this, 'confirmed');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user