10-05-2022

Laravel Livewire - use onClick (?)

If you got in trouble, to use native javascript onclick then use the following snippet.

<div wire:click="action" onclick="confirm('Are you sure you want to do this?') || event.stopImmediatePropagation()" class="btn btn-sm btn-success"
> 
  {{trans('global.add')}} 
</div>

Above the example shows the following:

  • div calls the components action method
  • after click, alert window pop-up and works like a charm!

Finally again:

onclick="confirm('Are you sure you want to do this?') || event.stopImmediatePropagation()" 

Have a nice day!

© 2022 PappZ. All rights reserved.