Confirm an action

What seems to be the problem: Use JavaScript’s confirm box before preforming an action. Even if cancel is clicked the actions is still preformed.

Steps to Reproduce:
Click on the remove user button and confirmation box pops up however the user is removed even if you click cancel.

<button type="button" wire:click="remove({{ $user->id }})" onclick="return confirm('Are you sure you want to remove the user from this group?');" >
    Remove User
</button>

Are you using the latest version of Livewire: Yes

Do you have any screenshots or code examples: See above…

I want a super simple solution to just confirm this operation to make sure a user isn’t accidentally deleted.

onclick="confirm('Are you sure you want to remove the user from this group?') || event.stopImmediatePropagation()"

and move the wire:click after. It won’t get hit if the confirmation is cancelled.

7 Likes

That’s perfect! Thanks!