jantinnerezo / livewire-alert

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

wire:loading and wire:target not working properly #144

Open hardevine opened 5 months ago

hardevine commented 5 months ago
// in Component Class

#[On('confirmed')]
public function confirmed(...$args)
{
    // saving data to db
}

public function confirmSubmit()
{

    $this->confirm('Are you sure ?', [
            'onConfirmed' => 'confirmed',
    ]);
}

<form wire:submit="confirmSubmit">
...

<button type="submit" class="btn btn-sm saveBtn text-uppercase me-4">
    <x-spinner wire:loading wire:target="__dispatch"/>
    Save
</button>

I'm using confirm dialog with sweetalert Loaders don't work unless i use __dispatch method in target for form submission. If there are multiple forms on page i can't separate them

brianalviano commented 5 months ago

same here

hardevine commented 5 months ago

workaround used with sweetalert's loader system:

// livewire-alert.php config
'showLoaderOnConfirm' => true,
'allowOutsideClick' => false,
public function confirmSubmit()
{

    $this->confirm('are you sure ?', [
            //'onConfirm' => 'confirmed',
            'preConfirm'=> 'formSubmitPreConfirm',
    ]);
}
async function formSubmitPreConfirm (event) {
Livewire.dispatch('confirmed');
      return new Promise(resolve => setTimeout(resolve, 10000));
};
// event dispatched so ajax can start while loader is spinning