Skip to content

Commit

Permalink
docs: fix this binding in onClick .then handler with arrow functi…
Browse files Browse the repository at this point in the history
…on (#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
  • Loading branch information
lloydlobo committed Apr 25, 2024
1 parent f9591c9 commit b176784
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion www/content/examples/confirm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit b176784

Please sign in to comment.