jantinnerezo / livewire-alert

SweetAlert2 wrapper for Livewire
https://livewire-alert.jantinnerezo.com
MIT License
709 stars 73 forks source link

Confirm not hitting confirmed #116

Closed cloudwales closed 1 year ago

cloudwales commented 1 year ago

Hi. I'm not quite sure what i'm missing here, hopfully its an easy one... But for some reason, when using confirm, it's not hitting the confirmed method!

The alert is popping up as it should, but when clicking the delete button its not hitting the confirmedDelete method. Any ideas?

    use LivewireAlert;

    protected $listeners = [
        'confirmedDelete'
    ];

    public function deleteUser()
    {
        $this->confirm('Are you sure you want to delete?', [
            'toast' => false,
            'showConfirmButton' => true,
            'confirmButtonText' => 'Delete',
            'onConfirmed' => 'confirmedDelete',
            'showCancelButton' => true,
            'cancelButtonText' => 'Cancel',
            'confirmButtonColor' => '#dc2626',
            'cancelButtonColor' => '#4b5563'
        ]);
    }

    public function confirmedDelete()
    {
        Log::info('Hit condirmed delete');

        if (User::all()->count() == 1) {
            $this->alert('warning', 'Please create another user before deleting this one');
            $this->showDeleteUserModal();
        } else {
            $this->user->delete();
            $this->flash('success', 'User deleted...', [], route('admin.settings.users.index'));
        }
    }
cloudwales commented 1 year ago

After a bit of playing i still have the same issue, but found i'm getting this error in the console.

2:538 Uncaught (in promise) TypeError: Livewire.find is not a function

Heres the updated code


protected $listeners = [
        'confirmDelete'
];

public function deleteUser()
{
        $this->confirm('Are you sure you want to delete?', [
            'confirmButtonText' => 'Delete',
            'onConfirmed' => 'confirmDelete',
        ]);
}

public function confirmDelete()
{
        Log::info('Hit condirmed delete');
}
cloudwales commented 1 year ago

Found the issue. I was loading livewire scripts twice. I knew it was something I had done wrong!!!