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:
Lloyd Lobo 2024-04-25 22:17:21 +05:30 committed by GitHub
parent f9591c9790
commit b176784f31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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');
}